title: React app detect if user refresh window or navigated away
body: <p>I need to be able to detect if the user refreshed the window or navigated away (say google.com) and then return to the page so I can trigger an event.</p>
  <p>I tried different onbeforeunload but it wasnt detecting it.</p>
  <p>I tried, this and it wasnt working or triggering the console.log.</p>
  <pre><code>componentDidUpdate()
  {
        window.addEventListener(&quot;onbeforeunload&quot;,function (){
          console.log('Page Refreshed')
       })
        
  }
  </code></pre>
  <p>However, that doesnt even trigger the console.log message.  I have also tried beforeunload and same results</p>
  <p>any ideas why?</p>