React Hook to handle local and session storage
npm install --save react-use-storage
See this hooks as a useState hooks that syncs with local/session storage.
☝️ NOTE: if the value of the key in the storage change from another portion of your code, the hook keep it in sync and re-render your component with the new value.
import {useLocalStorage} from "react-use-storage";
// ...
const [value, setValue, removeValue] = useLocalStorage("key", "default value");
import {useSessionStorage} from "react-use-storage";
// ...
const [value, setValue, removeValue] = useSessionStorage("key", "default value");