title: how to read cookie to maintain user session in react?
body: <p>I am trying to implement a user login with react. I'm sending a cookie created with cookie-parser from node to maintain the user session, but I can't access that value with react, I tried with the js-cookie library but it doesn't read the value of a cookie already created, it always returns an empty object.
  Any idea or suggestion? Thanks.</p>
  <p><a href="https://i.stack.imgur.com/w7GJs.png" rel="nofollow noreferrer">enter image description here</a></p>
  <pre><code>import React, { useEffect, useState } from 'react'
  import './style.scss'
  import {Link, Redirect} from 'react-router-dom'
  import axios from 'axios';
  import Cookies from 'js-cookie';
  
  export default function Login(props) {
  const [data, setData] = useState({})
  const [error,setError] = useState('')
  const [login, setLogin] = useState(false)
  
  
  const endpoint = &quot;http://localhost:4000/users/login&quot;
  
   axios.defaults.withCredentials = true
  
  function handleChange(e) {
      const {name,value} = e.target;
      setData({
  
          ...data,
          [name] : value
      })
  
  }
  
  useEffect(() =&gt;  {
    axios.get(endpoint).then(res =&gt; {
        console.log(res.data)
        
    }) }, [login])
  
  
  const read = Cookies.get()
  console.log(read)
  
  const handleSubmit = (e) =&gt; {
      e.preventDefault();
      axios.post(endpoint,data).then(res =&gt; {
        
              console.log(res)
              setLogin(true)
            
              }).catch(Error =&gt; {
              setError(&quot;error&quot;)
      })
  }
  </code></pre>