Skip to content

Commit

Permalink
feat: throw warning only if not on production
Browse files Browse the repository at this point in the history
  • Loading branch information
YossiSaadi committed Dec 9, 2024
1 parent f6a4a24 commit 4ee5c97
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const usePortalTarget = (portalTarget?: PortalTarget): Element | DocumentFragmen
if (typeof portalTarget === "string") {
const target = document.querySelector(portalTarget);
if (!target) {
console.warn(`Target with selector "${portalTarget}" not found. Falling back to document.body.`);
warn(`Target with selector "${portalTarget}" not found. Falling back to document.body.`);
return document.body;
}
return target;
Expand All @@ -27,7 +27,7 @@ const usePortalTarget = (portalTarget?: PortalTarget): Element | DocumentFragmen
return portalTarget.current;
}

console.warn("Invalid portalTarget provided. Falling back to document.body.");
warn("Invalid target provided. Falling back to document.body.");
return document.body;
};

Expand All @@ -39,3 +39,9 @@ const usePortalTarget = (portalTarget?: PortalTarget): Element | DocumentFragmen
};

export default usePortalTarget;

function warn(message: string): void {
if (process.env.NODE_ENV !== "production") {
console.warn(message);
}
}

0 comments on commit 4ee5c97

Please sign in to comment.