Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing getInitialValueInEffect to useLocalStorage hook in useDataTableColumns #560

Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3ed7c50
Merge pull request #486 from icflorescu/next
icflorescu Dec 7, 2023
448ffba
Merge pull request #487 from icflorescu/next
icflorescu Dec 8, 2023
0566e36
Merge pull request #493 from icflorescu/next
icflorescu Dec 21, 2023
4c6d45f
Merge pull request #494 from icflorescu/next
icflorescu Dec 21, 2023
5d3eaf8
Merge pull request #495 from icflorescu/next
icflorescu Dec 23, 2023
9d769fb
Merge pull request #497 from icflorescu/next
icflorescu Dec 28, 2023
04713c8
Merge pull request #498 from icflorescu/next
icflorescu Dec 29, 2023
030d194
Merge pull request #502 from icflorescu/next
icflorescu Jan 4, 2024
b5c1e56
Merge pull request #503 from icflorescu/next
icflorescu Jan 4, 2024
9d8c4eb
Merge pull request #509 from icflorescu/next
icflorescu Jan 8, 2024
c91e0d1
Merge pull request #510 from icflorescu/next
icflorescu Jan 10, 2024
afa18de
Merge pull request #511 from icflorescu/next
icflorescu Jan 10, 2024
4ff3393
Merge pull request #515 from icflorescu/next
icflorescu Jan 17, 2024
4873009
Merge pull request #516 from icflorescu/next
icflorescu Jan 17, 2024
890de70
Merge pull request #517 from icflorescu/next
icflorescu Jan 17, 2024
31d9dda
Merge pull request #523 from icflorescu/next
icflorescu Jan 20, 2024
ae7d0f7
Merge pull request #526 from icflorescu/next
icflorescu Jan 20, 2024
a493225
Merge pull request #527 from icflorescu/next
icflorescu Jan 21, 2024
2997ecf
Merge pull request #529 from icflorescu/next
icflorescu Jan 21, 2024
7ebae2c
Merge pull request #531 from icflorescu/next
icflorescu Jan 27, 2024
0b6c42b
Merge pull request #532 from icflorescu/next
icflorescu Jan 28, 2024
6165045
Merge pull request #538 from icflorescu/next
icflorescu Jan 31, 2024
872b9c3
Merge pull request #545 from icflorescu/next
icflorescu Feb 8, 2024
4e7491c
Merge pull request #546 from icflorescu/next
icflorescu Feb 8, 2024
44be814
Merge pull request #554 from icflorescu/next
icflorescu Feb 28, 2024
f88f4b0
Merge pull request #555 from icflorescu/next
icflorescu Mar 5, 2024
649e2a3
Merge pull request #556 from icflorescu/next
icflorescu Mar 5, 2024
43a0f7e
Merge pull request #557 from icflorescu/next
icflorescu Mar 5, 2024
66f0105
Merge pull request #558 from icflorescu/next
icflorescu Mar 5, 2024
851ecc8
Allow passing getInitialValueInEffect to useLocalStorage hook in useD…
Sajarin-M Mar 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions package/hooks/useDataTableColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type DataTableColumnWidth = Record<string, string | number>;
export const useDataTableColumns = <T>({
key,
columns = [],
getInitialValueInEffect = true,
}: {
/**
* The key to use in localStorage to store the columns order and toggle state.
Expand All @@ -27,6 +28,14 @@ export const useDataTableColumns = <T>({
* Columns definitions.
*/
columns: DataTableColumn<T>[];
/**
* 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)) || [];
Expand All @@ -49,21 +58,21 @@ export const useDataTableColumns = <T>({
const [columnsOrder, setColumnsOrder] = useLocalStorage<string[]>({
key: `${key}-columns-order`,
defaultValue: defaultColumnsOrder as string[],
getInitialValueInEffect: true,
getInitialValueInEffect,
});

// Store the columns toggle in localStorage
const [columnsToggle, setColumnsToggle] = useLocalStorage<DataTableColumnToggle[]>({
key: `${key}-columns-toggle`,
defaultValue: defaultColumnsToggle as DataTableColumnToggle[],
getInitialValueInEffect: true,
getInitialValueInEffect,
});

// Store the columns widths in localStorage
const [columnsWidth, setColumnsWidth] = useLocalStorage<DataTableColumnWidth[]>({
key: `${key}-columns-width`,
defaultValue: defaultColumnsWidth as DataTableColumnWidth[],
getInitialValueInEffect: true,
getInitialValueInEffect,
});

// we won't use the "remove" function from useLocalStorage() because
Expand Down