diff --git a/docs/examples/basic.tsx b/docs/examples/basic.tsx index acf50e9..73f35ad 100644 --- a/docs/examples/basic.tsx +++ b/docs/examples/basic.tsx @@ -15,9 +15,14 @@ export default () => { console.log('Demo unmount!!'); }, [], - ); - - const getContainer = customizeContainer ? () => divRef.current : undefined; + ) + + // const getContainer = customizeContainer ? () => divRef.current : undefined; + const getContainer = () => { + const el = document.createElement('div'); + document.body.appendChild(el); + return el + } const contentCls = customizeContainer ? '' : 'abs'; return ( diff --git a/src/Portal.tsx b/src/Portal.tsx index ea6ad35..e6aa6a5 100644 --- a/src/Portal.tsx +++ b/src/Portal.tsx @@ -79,7 +79,7 @@ const Portal = React.forwardRef((props, ref) => { // Tell component that we check this in effect which is safe to be `null` setInnerContainer(customizeContainer ?? null); - }); + }, [getContainer]); const [defaultContainer, queueCreate] = useDom( mergedRender && !innerContainer,