1import { useCallback, useState } from 'react';
4 * useLocalStorageState is useState but it persists to localStorage
7 * https://github.com/streamich/react-use/blob/master/src/useLocalStorage.ts
8 * https://usehooks.com/useLocalStorage/
10export default function useLocalStorageState(key, initialValue) {
11 const [state, _setState] = useState(() => {
13 const value = localStorage.getItem(key);
15 localStorage.setItem(key, JSON.stringify(initialValue));
18 return JSON.parse(value);
21 // if user is in private mode or has storage restriction
22 // localStorage can throw. JSON.parse and JSON.stringify
28 const setState = useCallback(
31 localStorage.setItem(key, JSON.stringify(value));
33 // if user is in private mode or has storage restriction
34 // localStorage can throw. Also JSON.stringify can throw.
42 return [state, setState];
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list