I want a function, to send a request to a server (don't care about response) before a user refreshes the page.
I've tried using the componentWillUnmount
approach but the page refresh doesn't call this function. e.g.
import React, { useEffect } from 'react';
const ComponentExample => () => {
useEffect(() => {
return () => {
// componentWillUnmount in functional component.
// Anything in here is fired on component unmount.
// Call my server to do some work
}
}, []) }
Does anyone have any ideas how to do this?
componentDidMount()
will fire when the component loads. I want a function to fire when the page is about to refresh. – Shanell