From fa4d85b4b655151296079e05e18a48290df14a46 Mon Sep 17 00:00:00 2001 From: liyang0612 <356514033@qq.com> Date: Fri, 11 Nov 2022 14:17:38 +0800 Subject: [PATCH] fix: (https://github.com/ant-design/ant-design/issues/38497) --- docs/examples/basic.tsx | 11 ++++++++--- src/Portal.tsx | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) 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,