I want to send a cleanup request to my API sever when the user leaves the website (actually closes the tab/browser, not just changes page in the SPA). Is there an idiomatic way to do this in an app using React with React Router? Will componentWillUnmount fire on page close? I assume not.
React doesn't do any special thing here for you. Just do that you usually do for this. Also, see answers to a related question
The best place to put this subscription code is the componentDidMount
lifecycle method. And do not forget to unsubscribe it on componentWillUnmount
to prevent leaks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With