title: localStorage in static NextJS site: ReferenceError: localStorage is not defined
body: <p>I'm trying to use localStorage on a NextJS static site but running into the localStorage is not defined error.</p>
  <p>My code for the component where the error shows, is:</p>
  <pre><code>export default function Category() {
  
  const [cart, setCart] = useState(
          localStorage.getItem(&quot;myCart&quot;) || &quot;&quot;
      );
  
   useEffect(() =&gt; {
          localStorage.setItem(&quot;myCart&quot;, cart);
      }, [cart]);
  
  function addItem() {
              setCart(&quot;item&quot;)   
      }
  
  return (
  &lt;&gt;
  &lt;button onClick={addItem}&gt;Add&lt;/button&gt;)
  &lt;/&gt;
  );
  }
  </code></pre>
  <p>Any idea if it's possible to use localStorage on a NextJS static site or if I'm doing something wrong?</p>
  <p>Thanks!</p>