title: React: Delete cookie when user closes the browser
body: <p>I'm using the library react-cookie (<a href="https://www.npmjs.com/package/react-cookie" rel="nofollow noreferrer">https://www.npmjs.com/package/react-cookie</a>) and I want to delete the user cookies when the browser or tab is closed. I used ComponentWillUnmount in my Approuter, but that doesn't work when the browser is closed. Anyone know how to achieve this?</p>
  
  <pre><code>import React from 'react';
  import {Router, Route, Switch} from 'react-router-dom';
  import history from '../data/history';
  import { withCookies, Cookies } from 'react-cookie';
  import { instanceOf } from 'prop-types';
  
  
  class AppRouter extends React.Component{
  
  static propTypes = {
      cookies: instanceOf(Cookies).isRequired
  };
  
  
  constructor(props){
      super(props)
  }
  
  componentWillMount(){
      const {cookies} = this.props;
      cookies.remove('userInfo');
  }
  
  render(){
      return(
          &lt;Router history={history}&gt;
              &lt;div&gt;
                  &lt;Header/&gt;
                  &lt;div className="main-container"&gt;
                      &lt;Switch&gt;
                          //routes
                      &lt;/Switch&gt;
                      &lt;Footer/&gt;
                  &lt;/div&gt; 
              &lt;/div&gt;
          &lt;/Router&gt;
      );
  }
  }
  
  export default withCookies(AppRouter);
  </code></pre>
  
  <p>The router does receive the cookies so why can't I remove it with componentWillUnmount? And how do I remove them? </p>