Skip to content

Instantly share code, notes, and snippets.

View NoahDavidATL's full-sized avatar

Noah David NoahDavidATL

View GitHub Profile
@ericelliott
ericelliott / use-local-storage.js
Created March 30, 2020 23:34
A localStorage drop-in replacement for useState
import { useState } from 'react';
const configureLocalStorage = key => initialValue => {
const [state, setState] = useState(() => {
try {
const value = localStorage.getItem(key);
return value ? JSON.parse(value) : initialValue;
} catch (e) {
console.log(e);
return initialValue;