title: Is there a way to get a useEffect cleanup to run when a user closes the webpage?
body: <p>So for some reason, if I wanted to run a function to update a database when the user leaves a page, I can do that with a useEffect return/cleanup function.  But is there a way to do that if they close the page/browser?</p>
  <pre><code>  useEffect(() =&gt; {
      return () =&gt; {
        window.open(&quot;https://www.google.com&quot;, &quot;_blank&quot;);
      };
    }, []);
  </code></pre>
  <p>I tried testing like so, but never seemed to work.  So I am wondering if there is a way to do this.</p>