I would like to detect a refresh page (f5 or the refresh button in the browser) in react in order to perform function. Basically i would like to call an API when the refresh is pushed and to call this API, i need some state value. Does someone has an idea how to do that? Thanks
EDIT:
useEffect(() => {
console.log("use effect called");
window.addEventListener('beforeunload', handleEndConcert);
return () => {
// hit endpoint to end show
window.removeEventListener('beforeunload', handleEndConcert);
//handleEndConcert();
}
}, []);
const handleEndConcert = () => {
console.log('Stop this');
console.log(selectedFile);
}