diff --git a/src/index.tsx b/src/index.tsx index c6b81a8..c3d921a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -8,6 +8,7 @@ import { depthFirstSearch } from './utils'; import useSafeState from './utils/useSafeState'; import useLocalColumns from './utils/useLocalColumns'; import useGetDataIndexColumns, { GETKEY, ResizableUniqIdPrefix } from './utils/useGetDataIndexColumns'; +import useMemoizedFn from './utils/useMemoizedFn'; export type ColumnsState = { width: number; @@ -73,7 +74,7 @@ function useTableResizableHeader const [resizableColumns, setResizableColumns] = useSafeState([]); - const { localColumns: columns, resetColumns } = useLocalColumns({ + const { localColumns: columns, resetLocalColumns } = useLocalColumns({ columnsState, columns: columnsProp, resizableColumns, @@ -83,6 +84,11 @@ function useTableResizableHeader const [triggerRender, forceRender] = React.useReducer((s) => s + 1, 0); + const resetColumns = useMemoizedFn(() => { + widthCache.current = new Map(); + resetLocalColumns(); + }); + const onMount = React.useCallback( (id: React.Key | undefined) => (width?: number) => { if (width) { diff --git a/src/utils/useLocalColumns.ts b/src/utils/useLocalColumns.ts index 2236985..8f9ede5 100644 --- a/src/utils/useLocalColumns.ts +++ b/src/utils/useLocalColumns.ts @@ -96,13 +96,13 @@ function useLocalColumns>({ /** * reset */ - const resetColumns = useMemoizedFn(() => { + const resetLocalColumns = useMemoizedFn(() => { setLocalColumns([...(columnsProp || [])]); }); return { localColumns: useMemo(() => localColumns, [localColumns]), - resetColumns, + resetLocalColumns, }; }