title: React - check when tab or browser is closed, but not on refresh
body: <p>I want to disconnect all my users when the tab is closing or the browser is getting closed, so far so good. But when I refresh the page, all my users get disconnected too, this should not happen on refresh. Is it possible to avoid to execute this event on refresh? I saw some users doing with localStorage, but I still didn't get the point.</p>
  
  <pre><code>componentDidMount() {
    this.beforeUnloadListener();
  }
  
  
  beforeUnloadListener = () =&gt; {
    window.addEventListener("beforeunload", (ev) =&gt; {
      ev.preventDefault();
      // code to logout user
    });
  };
  </code></pre>