## useLocalState Custom Hook

    import React from "react";

    function useLocalState(key, initialValue = "") {
      const [state, setState] = React.useState(initialValue);

      React.useEffect(() => {
        const value = localStorage.getItem(key);
        update(value || initialValue);
      }, [key]);

      React.useEffect(() => {
        function handler({ key: eventKey, newValue }) {
          if (eventKey === key && newValue !== state) update(newValue);
        }
        window.addEventListener("storage", handler);
        return () => window.removeEventListener(handler);
      }, [key]);

      function update(newState) {
        localStorage.setItem(key, newState);
        setState(newState);
      }

      function clear() {
        localStorage.setItem(key, initialValue);
        setState(initialValue);
      }

      return [state, update, clear];
    }

    export default useLocalState;