MCPcopy Create free account
hub / github.com/BetterBahn/betterbahn / initialize

Function initialize

components/SearchForm/useLocalStorage.ts:6–18  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4 const [value, setValueInternal] = useState(() => initialValue);
5
6 const initialize = () => {
7 if (typeof window === "undefined") {
8 return initialValue;
9 }
10
11 const stringified = window.localStorage.getItem(key);
12
13 if (stringified === null) {
14 return initialValue;
15 }
16
17 return JSON.parse(stringified) as T;
18 };
19
20 // prevents hydration error so that state is only initialized after server is defined
21 useEffect(() => {

Callers 1

useLocalStorageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected