blob: d7e00408751f0221543e3c39fd750d32d14324f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
import { useLocalStorage } from "@mantine/hooks";
import { useCallback } from "react";
export const uiPageSizeKey = "storage-ui-pageSize";
export function useUpdateLocalStorage() {
return useCallback((newVals: LooseObject) => {
for (const key in newVals) {
const value = newVals[key];
localStorage.setItem(key, value);
}
}, []);
}
export function getPageSize(storage: Storage): number {
const defaultValue = 50;
const value = storage.getItem(uiPageSizeKey);
if (value === null) {
return defaultValue;
}
return JSON.parse(value);
}
export function usePageSize() {
return useLocalStorage({ key: uiPageSizeKey, defaultValue: 50 });
}
|