From 851ecc8e2f1a719180db4559e191f977a3cbfe27 Mon Sep 17 00:00:00 2001 From: Sajarin M Date: Fri, 15 Mar 2024 17:29:20 +0530 Subject: [PATCH] Allow passing getInitialValueInEffect to useLocalStorage hook in useDataTableColumns --- package/hooks/useDataTableColumns.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/package/hooks/useDataTableColumns.ts b/package/hooks/useDataTableColumns.ts index c3a2db707..1d95e9d0a 100644 --- a/package/hooks/useDataTableColumns.ts +++ b/package/hooks/useDataTableColumns.ts @@ -18,6 +18,7 @@ type DataTableColumnWidth = Record; export const useDataTableColumns = ({ key, columns = [], + getInitialValueInEffect = true, }: { /** * The key to use in localStorage to store the columns order and toggle state. @@ -27,6 +28,14 @@ export const useDataTableColumns = ({ * Columns definitions. */ columns: DataTableColumn[]; + /** + * Columns definitions. + */ + /** + * If set to true, value will be update is useEffect after mount. + * @default true + */ + getInitialValueInEffect?: boolean; }) => { // Default columns id ordered is the order of the columns in the array const defaultColumnsOrder = (columns && columns.map((column) => column.accessor)) || []; @@ -49,21 +58,21 @@ export const useDataTableColumns = ({ const [columnsOrder, setColumnsOrder] = useLocalStorage({ key: `${key}-columns-order`, defaultValue: defaultColumnsOrder as string[], - getInitialValueInEffect: true, + getInitialValueInEffect, }); // Store the columns toggle in localStorage const [columnsToggle, setColumnsToggle] = useLocalStorage({ key: `${key}-columns-toggle`, defaultValue: defaultColumnsToggle as DataTableColumnToggle[], - getInitialValueInEffect: true, + getInitialValueInEffect, }); // Store the columns widths in localStorage const [columnsWidth, setColumnsWidth] = useLocalStorage({ key: `${key}-columns-width`, defaultValue: defaultColumnsWidth as DataTableColumnWidth[], - getInitialValueInEffect: true, + getInitialValueInEffect, }); // we won't use the "remove" function from useLocalStorage() because