title: Get cookie with react
body: <p>I need to know if my user is connected or not. For that I want to read the cookies that I set in the server side with express-session :</p>
  <pre class="lang-js prettyprint-override"><code>app.use(session({
      secret: 'crypted key',
      resave: false,
      saveUninitialized: true,
      cookie: { secure: false } // Put true if https
  }))
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>app.post('/connect_user', (req, res) =&gt; {
      req.session.cookie.username = req.body.username
      findUserData('username', req.body.username, req, (userData) =&gt; {
          req.session.cookie.id = userData.id
          req.session.cookie.username = userData.username
          res.redirect('/profil')
      })
  })
  </code></pre>
  <p>I tried to use <code>react-cookie</code> but it doesn't work even though I copy-pasted the npm <code>react-cookie</code> docs example:</p>
  <pre><code>import React from 'react';
  import Landing from './Landing';
  import Home from './Home';
  import Profil from './Profil';
  import { BrowserRouter as Router, Route } from 'react-router-dom';
  import { instanceOf } from 'prop-types';
  import { Cookies } from 'react-cookie';
  
  class App extends React.Component {
      static propTypes = {
          cookies: instanceOf(Cookies).isRequired
        };
       
        constructor(props) {
          super(props);
       
          const { cookies } = props;
          this.state = {
            username: cookies.get('username')
          };
        }
      render() {
          console.log(this.state.name) 
          let homePage = (!this.state.username) ? &lt;Landing/&gt; : &lt;Home/&gt;
          return (
              &lt;Router&gt;
                  &lt;div&gt;
                      &lt;Route exact path='/' component={homePage}&gt;&lt;/Route&gt;
                      &lt;Route path='/profil' component={Profil}&gt;&lt;/Route&gt;
                  &lt;/div&gt;
              &lt;/Router&gt;
          )
      }
  }
  
  export default App;
  </code></pre>
  <p>It's weird because <code>document.cookie</code> renders the correct result, but I don't know how handle it:</p>
  <pre><code>PHPSESSID=0nv9ic8h7pv2b63lu4v7eg3mop; user_id=21; username=Ugo; SL_G_WPT_TO=fr; SL_GWPT_Show_Hide_tmp=undefined; SL_wptGlobTipTmp=undefined
  </code></pre>