Skip to content

Commit

Permalink
fix: localColumns reset when resizableColumns length = 0
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed Jan 11, 2022
1 parent 32e68ee commit 7e255cb
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/utils/useLocalColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ function useLocalColumns<T extends ColumnOriginType<T>>({
const [localColumns, setLocalColumns] = React.useState<T[] | undefined>(initLocalColumns);

useEffect(() => {
if (!localColumns?.length) {
setLocalColumns(columnsProp);
} else {
setLocalColumns(initLocalColumns());
}
setLocalColumns(initLocalColumns());
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [columnsProp]);

Expand All @@ -70,7 +66,7 @@ function useLocalColumns<T extends ColumnOriginType<T>>({
React.useEffect(() => {
const { persistenceType, persistenceKey } = columnsState || {};

if (!persistenceKey || !persistenceType || !resizableColumns) {
if (!persistenceKey || !persistenceType || !resizableColumns?.length) {
return;
}
if (typeof window === 'undefined') return;
Expand All @@ -92,7 +88,8 @@ function useLocalColumns<T extends ColumnOriginType<T>>({
} catch (error) {
console.error(error);
}
}, [columnsState, resizableColumns]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [resizableColumns]);

/**
* reset
Expand Down

0 comments on commit 7e255cb

Please sign in to comment.