Skip to content

Commit

Permalink
enhancement(portal): add unstable_skipInitialRender (#902)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaance committed Apr 20, 2022
1 parent 93a3f8d commit a8f38a4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/portal/src/index.tsx
Expand Up @@ -26,6 +26,7 @@ const Portal: React.FC<PortalProps> = ({
children,
type = "reach-portal",
containerRef,
unstable_skipInitialRender,
}) => {
let mountNode = React.useRef<HTMLDivElement | null>(null);
let portalNode = React.useRef<HTMLElement | null>(null);
Expand Down Expand Up @@ -72,6 +73,15 @@ const Portal: React.FC<PortalProps> = ({
};
}, [type, forceUpdate, containerRef]);

let [hydrated, setHydrated] = React.useState(false);
React.useEffect(() => {
setHydrated(true);
}, []);

if (unstable_skipInitialRender && !hydrated) {
return;
}

return portalNode.current ? (
createPortal(children, portalNode.current)
) : (
Expand Down Expand Up @@ -103,6 +113,7 @@ type PortalProps = {
* @see Docs https://reach.tech/portal#portal-containerRef
*/
containerRef?: React.RefObject<Node>;
unstable_skipInitialRender?: boolean;
};

if (__DEV__) {
Expand Down

0 comments on commit a8f38a4

Please sign in to comment.