React Custom Hook useLocalStorage

React Hooks have taken the world by storm! No need for clunky classes and weird quirks about the keyword this. Now we can use hooks and customize how we tap into the React component lifecycle.

import { useState } from 'react';function useLocalStorage(key, initialValue) {
const [storedValue, setStoredValue] = useState(() => {
try {
const item =…