diff --git a/packages/antd/src/form-item/index.tsx b/packages/antd/src/form-item/index.tsx index 6a469b39f00..6140829157d 100644 --- a/packages/antd/src/form-item/index.tsx +++ b/packages/antd/src/form-item/index.tsx @@ -90,6 +90,8 @@ function useOverflow< const [overflow, setOverflow] = useState(false) const containerRef = useRef() const contentRef = useRef() + const layout = useFormLayout() + const labelCol = JSON.stringify(layout.labelCol) useEffect(() => { if (containerRef.current && contentRef.current) { @@ -101,7 +103,7 @@ function useOverflow< if (overflow) setOverflow(false) } } - }, []) + }, [labelCol]) return { overflow, diff --git a/packages/antd/src/form-layout/useResponsiveFormLayout.ts b/packages/antd/src/form-layout/useResponsiveFormLayout.ts index af92731b17d..2dcecfd308d 100644 --- a/packages/antd/src/form-layout/useResponsiveFormLayout.ts +++ b/packages/antd/src/form-layout/useResponsiveFormLayout.ts @@ -82,7 +82,9 @@ export const useResponsiveFormLayout: IUseResponsiveFormLayout = (props) => { const [layoutProps, setLayout] = useState(props) const updateUI = () => { - setLayout(calculateProps(ref.current, props)) + if (ref.current) { + setLayout(calculateProps(ref.current, props)) + } } useEffect(() => { diff --git a/packages/element/src/form-layout/useResponsiveFormLayout.ts b/packages/element/src/form-layout/useResponsiveFormLayout.ts index 1d55a39c88e..5ec43153509 100644 --- a/packages/element/src/form-layout/useResponsiveFormLayout.ts +++ b/packages/element/src/form-layout/useResponsiveFormLayout.ts @@ -89,7 +89,9 @@ export const useResponsiveFormLayout: IUseResponsiveFormLayout = ( const layoutProps = ref(props) const updateUI = () => { - layoutProps.value = calculateProps(root.value, props) + if (root.value) { + layoutProps.value = calculateProps(root.value, props) + } } onMounted(() => { diff --git a/packages/next/src/form-item/index.tsx b/packages/next/src/form-item/index.tsx index e6f88820dc4..01d34327df2 100644 --- a/packages/next/src/form-item/index.tsx +++ b/packages/next/src/form-item/index.tsx @@ -90,6 +90,8 @@ function useOverflow< const [overflow, setOverflow] = useState(false) const containerRef = useRef() const contentRef = useRef() + const layout = useFormLayout() + const labelCol = JSON.stringify(layout.labelCol) useEffect(() => { if (containerRef.current && contentRef.current) { @@ -101,7 +103,7 @@ function useOverflow< if (overflow) setOverflow(false) } } - }, []) + }, [labelCol]) return { overflow, diff --git a/packages/next/src/form-layout/useResponsiveFormLayout.ts b/packages/next/src/form-layout/useResponsiveFormLayout.ts index 9095d5ec3fd..df832a33584 100644 --- a/packages/next/src/form-layout/useResponsiveFormLayout.ts +++ b/packages/next/src/form-layout/useResponsiveFormLayout.ts @@ -82,7 +82,9 @@ export const useResponsiveFormLayout: IUseResponsiveFormLayout = (props) => { const [layoutProps, setLayout] = useState(props) const updateUI = () => { - setLayout(calculateProps(ref.current, props)) + if (ref.current) { + setLayout(calculateProps(ref.current, props)) + } } useEffect(() => {