title: setState not working inside useEffect hook and token is showing null everytime
body: <p>I am building a wrapper which will see if token is present or not in the localstorage then
  it will render the component otherwise redirect the user to the login page.
  The auth and token state are not getting changed...</p>
  <pre><code>import Home from &quot;./Home&quot;;
  import { Redirect } from &quot;react-router-dom&quot;;
  import { useEffect, useState } from &quot;react&quot;;
  
  function Protected_home() {
      const[token , setToken] = useState(null)
      const [auth,setAuth] = useState(false)
  
      useEffect(()=&gt;{
          setToken(localStorage.getItem(&quot;noty__auth__token&quot;)) //not working
          console.log(&quot;token fetched&quot;) // getting a log the token
      },[])
  
      useEffect(()=&gt;{
          setAuth(true) // setting auth to true
      },[token])
  
      useEffect(()=&gt;{
          alert(token) // getting null
      },[auth])
  
      // conditional rendering of the components
      if(auth){
          return &lt;Home/&gt;
      }else{
          return &lt;Redirect to={{pathname:&quot;/&quot;}}/&gt;
      }
  }
  
  export default Protected_home
  </code></pre>