MCPcopy
hub / github.com/portainer/portainer / useLocalStorage

Function useLocalStorage

app/react/hooks/useLocalStorage.ts:9–25  ·  view source on GitHub ↗
(
  key: string,
  defaultValue: T,
  storage = localStorage
)

Source from the content-addressed store, hash-verified

7}
8
9export function useLocalStorage<T>(
10 key: string,
11 defaultValue: T,
12 storage = localStorage
13): [T, (value: T) => void] {
14 const [value, setValue] = useState(get<T>(key, defaultValue, storage));
15
16 const handleChange = useCallback(
17 (value) => {
18 setValue(value);
19 set<T>(key, value, storage);
20 },
21 [key, storage]
22 );
23
24 return useMemo(() => [value, handleChange], [value, handleChange]);
25}
26
27export function get<T>(
28 key: string,

Callers 3

useSearchBarStateFunction · 0.90
useHomePageFilterFunction · 0.90
usePaginationLimitStateFunction · 0.90

Calls 3

setValueFunction · 0.85
setFunction · 0.85
getFunction · 0.70

Tested by

no test coverage detected