title: How to do server call on browser close/tab close in react
body: <p>I am trying to do server call to save data using redux saga in react js on browser close/tab close using JavaScript events, but it closes the browser before calling service.</p>
  
  <pre><code>onClose = () =&gt;{
    return this.props.saveData()  // saveData will save data using redux saga.
  }
  
  componentDidMount() {
    window.addEventListener('beforeunload',this.close);
  }
  
  componentWillMount() {
    window.addEventListener('beforeunload',this.onClose);
  }
  </code></pre>
  
  <p>I expect to call service and save data before closing browser or tab but it closes browser before calling service to save data</p>