title: Can you use an 'beforeunload' listener in an export default function? If so how?
body: <p>All examples I am seeing online are using React Components. I am a newbie to react.  So any explanation will be helpful, and what I should do to achieve this.</p>
  <pre><code>export default function Review() {
  ...
  
  useEffect(() =&gt; {
  console.log(&quot;useeffect called&quot;)
  
  window.addEventListener(&quot;beforeunload&quot;, save());
  
  }, []);
  
  ...
  
  return (...);
  </code></pre>
  <p>Here is a CodeSandbox.io link.  Here you will find that I have 2 pages 1 home the other dashboard.</p>
  <p>When I go to dashboard.  I get the Alert.  But Leaving Dashboard I do not get the Alert Message.  beforeunload is not working how I expect it to.</p>
  <p><a href="https://codesandbox.io/s/react-router-basic-forked-8uvvi?file=/" rel="nofollow noreferrer">https://codesandbox.io/s/react-router-basic-forked-8uvvi?file=/</a></p>