title: Detect window close on React
body: <p>I am developing a SCORM  course using React and I must detect when user closes the tab to send the correct event to Lms</p>
  
  <p>I tried to search for similar questions, and even following the answers of this thread <a href="https://stackoverflow.com/questions/39094138/reactjs-event-listener-beforeunload-added-but-not-removed">reactjs event listener beforeunload added but not removed</a> I could not make it work, onbeforeunload is just not called.</p>
  
  <p>Also componentwillunmount do not works when user closes the window directly.</p>
  
  <p>Any suggestions about how I could achieve this?</p>