title: React | How to detect Page Refresh (F5)
body: <p>I'm using <a href="https://reactjs.org/docs/hello-world.html" rel="noreferrer">React js</a>. I need to detect <code>page refresh</code>. When user hits refresh icon or press F5, I need to find out the event.</p>
  
  <p>I tried with <a href="https://stackoverflow.com/questions/47368578/react-js-detect-page-refresh">stackoverflow post</a> by using javascript functions</p>
  
  <p>I used javascript function <code>beforeunload</code> still no luck.</p>
  
  <pre><code>onUnload(event) { 
    alert('page Refreshed')
  }
  
  componentDidMount() {
    window.addEventListener("beforeunload", this.onUnload)
  }
  
  componentWillUnmount() {
     window.removeEventListener("beforeunload", this.onUnload)
  }
  </code></pre>
  
  <p>here I have full code on <a href="https://stackblitz.com/edit/react-vtu3x3" rel="noreferrer">stackblitz</a></p>