From 7e255cb82e0cfb8c6b2d405fc653611440ce65d4 Mon Sep 17 00:00:00 2001 From: hemengke <23536175@qq.com> Date: Tue, 11 Jan 2022 18:10:58 +0800 Subject: [PATCH] fix: localColumns reset when resizableColumns length = 0 --- src/utils/useLocalColumns.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/utils/useLocalColumns.ts b/src/utils/useLocalColumns.ts index 946f277..20d6fba 100644 --- a/src/utils/useLocalColumns.ts +++ b/src/utils/useLocalColumns.ts @@ -56,11 +56,7 @@ function useLocalColumns>({ const [localColumns, setLocalColumns] = React.useState(initLocalColumns); useEffect(() => { - if (!localColumns?.length) { - setLocalColumns(columnsProp); - } else { - setLocalColumns(initLocalColumns()); - } + setLocalColumns(initLocalColumns()); // eslint-disable-next-line react-hooks/exhaustive-deps }, [columnsProp]); @@ -70,7 +66,7 @@ function useLocalColumns>({ React.useEffect(() => { const { persistenceType, persistenceKey } = columnsState || {}; - if (!persistenceKey || !persistenceType || !resizableColumns) { + if (!persistenceKey || !persistenceType || !resizableColumns?.length) { return; } if (typeof window === 'undefined') return; @@ -92,7 +88,8 @@ function useLocalColumns>({ } catch (error) { console.error(error); } - }, [columnsState, resizableColumns]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [resizableColumns]); /** * reset