mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-17 01:32:45 +00:00
Handle unsaved warning with onbeforeunload
This commit is contained in:
@@ -78,13 +78,15 @@ const HomePage =(props)=>{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener('beforeunload', handleBeforeUnload);
|
const previousBeforeUnload = window.onbeforeunload;
|
||||||
|
|
||||||
|
window.onbeforeunload = handleBeforeUnload;
|
||||||
|
|
||||||
document.addEventListener('keydown', handleControlKeys);
|
document.addEventListener('keydown', handleControlKeys);
|
||||||
|
|
||||||
return ()=>{
|
return ()=>{
|
||||||
document.removeEventListener('keydown', handleControlKeys);
|
document.removeEventListener('keydown', handleControlKeys);
|
||||||
window.removeEventListener('beforeunload', handleBeforeUnload);
|
window.onbeforeunload = previousBeforeUnload;
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user