Warn the user when they are quitting the workflow page (#1172)

This commit is contained in:
Shuchang Zheng
2024-11-11 10:22:36 -08:00
committed by GitHub
parent a149a4675b
commit b768ca0e86
2 changed files with 26 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { useEffect } from "react";
function useShouldNotifyWhenClosingTab() {
useEffect(() => {
function f(event: BeforeUnloadEvent) {
// this function is here to have a stable reference only
// Recommended
event.preventDefault();
// Included for legacy support, e.g. Chrome/Edge < 119
// refer to https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
event.returnValue = true;
}
window.addEventListener("beforeunload", f);
return () => {
window.removeEventListener("beforeunload", f);
};
}, []);
}
export { useShouldNotifyWhenClosingTab };