In my React app, I have the following useEffect and cleanup.
useEffect(() => {
if (pageLoad) {
window.addEventListener('beforeunload', (e) => {
localStorage.removeItem(SOME_KEY);
});
return () => {
window.removeEventListener('beforeunload');
}
}
}, [pageLoad]);
However, I get the following error. Is there some issue with the removeEventListener ?
Failed to execute 'removeEventListener' on 'EventTarget': 2 arguments required, but only 1 present
You can pass same function to removeEventListener