title: Check cookie is exist in React
body: <p>I have used <code>js-cookie</code> in my <code>React</code> application, here I just use a simple condition to check whether the cookie is matched or not and push history to the following route, here is my code:</p>
  <pre><code>const readCookie = () =&gt; {
      let cookie = false;
      if(cookie = Cookies.get(&quot;isLogged&quot;)){
          history.push('/Homepage');
          setAuthenticated(true);
      }else{
          history.push('/');
      }
  }
  useEffect(() =&gt; {
      readCookie()
  },[]);
  </code></pre>
  <p>But the problem is, if I have many routes, so I just have to write many <code>if conditions</code> as much as my existing routes to check and push to that specific route, I think it doesn't make sense to do that. So, I just want to know that is there any easier way? To check the cookies and push to their paths or routes.</p>