title: Set cookie from API response in React
body: <p>I have a React app, and an API. When i <code>POST</code> data to APIs login url API responses me back with cookie on successful login, which I have to set, so in each next request user will send this cookie. But I can't find a method to get it from response. <a href="https://i.stack.imgur.com/aHAX1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aHAX1.png" alt="enter image description here"></a></p>
  
  <p>I want to set <code>sessionid</code>, but I can't reach it within code. I tried to do </p>
  
  <pre><code>Cookies.set('sessionid', response.headers['sessionid']);
  </code></pre>
  
  <p>But it sets <code>undefined</code>. <code>console.log(response.headers)</code> also gives me <code>{content-length: "31", content-type: "application/json"}</code>. Do I do something wrong?</p>
  
  <p>Sender function:</p>
  
  <pre><code>formSender() {
      const url_to_send = `${this.state.api_base_url}:${this.state.api_base_port}${this.state.api_user_url}/login/`;
      axios.post(url_to_send, `username=${this.state.username}&amp;password=${this.state.password}`, {headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
          .then((response) =&gt; {
          // I need to set the cookie here
              this.setState({
                  login_success: response.status === 200,
                  request_sent: false
              });
          })
  };
  </code></pre>