GOAL: Persist the value to local storage
ecumene opened this issue · comments
const [value, setValue] = useState(localstorage.getItem("..."))
useEffect(() => {
localstorage.setItem("...", value);
}, [value]);
Sorry to lurk and nitpic, but this should probably be:
const [value, setValue] = useState(() => localstorage.getItem("..."))
by passing a arrow function instead of just passing in the get item, it will only call the function once on initial render of the component, not attempt to run getItem every time the component renders, even though this is only used to seed useState and isn't useful after the first render