title: How to save darkMode in local storage in React?
body: <p>I want to save in <strong>local storage</strong> what theme the user has chosen - light or dark, so that when the page refreshes the theme is still current with the user's choice. I tried using the useEffect hook for this, but I am probably doing something wrong.
  I have included the code below:</p>
  <pre><code>function App() {
  // Theme
      const [theme, setTheme] = useState('light');
      const checkTheme = () =&gt; theme === 'light' ? setTheme('dark') : setTheme('light') ;
  
  // Amount of Portions
  const [amountOfPortions , setAmountOfPortions] = useState(1);
  
  const updateAmountOfPortions = (dataFromChild) =&gt; {
      setAmountOfPortions(dataFromChild);
  };
  
  return (
      &lt;div className={`app wrapper app__bgc--${theme}`}&gt;
          &lt;Switch onChange={checkTheme} color=&quot;primary&quot;/&gt;
          &lt;MainCard update={updateAmountOfPortions}/&gt;
          &lt;Recipe value={amountOfPortions}/&gt;
      &lt;/div&gt;
      
  )};
  </code></pre>