title: Explicitly clear localstorage on browser close for React
body: <p>I hve an app with React front and java back. I'm using JWT and keep the token in localstorage. How to clear localstorage when I close the whole browser? For react.
  My menu component is here (the one I change based on the presence of the token. isUserLoggedIn checks if there is a token.</p>
  
  <pre><code>class MenuComponent extends Component {
    componentWillUnmount() {
      localStorage.clear();
    }
    render() {
      const isUserLoggedIn = AuthenticationService.isUserLoggedIn();
      return (
        &lt;Navbar collapseOnSelect expand='lg' bg='dark' variant='dark'&gt;
          &lt;Navbar.Brand href=''&gt;MAP-Runner&lt;/Navbar.Brand&gt;
          &lt;Navbar.Toggle aria-controls='responsive-navbar-nav' /&gt;
          &lt;Navbar.Collapse id='responsive-navbar-nav'&gt;
            &lt;Nav&gt;
              {!isUserLoggedIn &amp;&amp; (
                &lt;li&gt;
                  &lt;Link className='nav-link' to='/login'&gt;
                    Вход
                  &lt;/Link&gt;
                &lt;/li&gt;
              )}
              {isUserLoggedIn &amp;&amp; (
                &lt;li&gt;
                  &lt;Link className='nav-link' to='/calculations'&gt;
                    Расчеты
                  &lt;/Link&gt;
                  &lt;Link
                    className='nav-link'
                    to={{ pathname: `/calculation-types` }}
                  &gt;
                    Типы расчетов
                  &lt;/Link&gt;
                  &lt;Link className='nav-link' to={{ pathname: `/group-settings` }}&gt;
                    Настройки кластеров
                  &lt;/Link&gt;
                  &lt;Link className='nav-link' to={{ pathname: `/ost-docs` }}&gt;
                    Док-ты остатков
                  &lt;/Link&gt;
                  &lt;Link className='nav-link' to={{ pathname: `/artlists` }}&gt;
                    Списки артикулов
                  &lt;/Link&gt;
                  &lt;Link className='nav-link' to={{ pathname: `/color-schemas` }}&gt;
                    Цветовые схемы
                  &lt;/Link&gt;
                  &lt;Link
                    className='nav-link'
                    to='/logout'
                    onClick={AuthenticationService.logout}
                  &gt;
                    Выход
                  &lt;/Link&gt;
                &lt;/li&gt;
              )}
            &lt;/Nav&gt;
          &lt;/Navbar.Collapse&gt;
        &lt;/Navbar&gt;
      );
    }
  }
  
  export default withRouter(MenuComponent);
  </code></pre>