()
| 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(() => { |