text: import { useState } from "react";
  
  export default function useLocalStorage(key, initialValue) {
    const [storedValue, setStoredValue] = useState(() => {
      try {
        let item = window.localStorage.getItem(key);
        if (!item || !JSON.parse(item)) {
          window.localStorage.setItem(key, JSON.stringify(initialValue));
        }
  
        return item ? JSON.parse(item) : initialValue;
      } catch (error) {
        return initialValue;
      }
    });
  
    const setValue = (value) => {
      try {
        setStoredValue(value);
        window.localStorage.setItem(key, JSON.stringify(value));
      } catch (error) {
        // @todo handle error
        console.log(error);
      }
    };
  
    return [storedValue, setValue];
  }
  