aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/components/hooks/useWindowLeave.ts
diff options
context:
space:
mode:
Diffstat (limited to 'FrontEnd/src/components/hooks/useWindowLeave.ts')
-rw-r--r--FrontEnd/src/components/hooks/useWindowLeave.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/FrontEnd/src/components/hooks/useWindowLeave.ts b/FrontEnd/src/components/hooks/useWindowLeave.ts
new file mode 100644
index 00000000..08777e30
--- /dev/null
+++ b/FrontEnd/src/components/hooks/useWindowLeave.ts
@@ -0,0 +1,22 @@
+import { useEffect } from "react";
+
+import { useC, Text } from "../common";
+
+export default function useWindowLeave(
+ allow: boolean,
+ message: Text = "timeline.confirmLeave",
+) {
+ const c = useC();
+
+ useEffect(() => {
+ if (!allow) {
+ window.onbeforeunload = () => {
+ return c(message);
+ };
+
+ return () => {
+ window.onbeforeunload = null;
+ };
+ }
+ }, [allow, message]);
+}