fix: antd table ref bug (#3029)

This commit is contained in:
jack zhang 2023-11-13 17:49:24 +08:00 committed by GitHub
parent 647c8ccdaa
commit 4209babb47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,7 @@ import { useCallback, useRef, useState } from 'react';
export const useTableSize = () => {
const [height, setTableHeight] = useState(0);
const [width, setTableWidth] = useState(0);
const elementRef = useRef<HTMLDivElement>();
const elementRef = useRef<HTMLDivElement>(null);
const calcTableSize = useCallback(() => {
if (!elementRef.current) return;
@ -21,7 +21,7 @@ export const useTableSize = () => {
}, []);
const tableSizeRefCallback: React.RefCallback<HTMLDivElement> = (ref) => {
elementRef.current = ref;
elementRef.current = ref && ref.children ? (ref.children[0] as HTMLDivElement) : null;
calcTableSize();
};