plane/apps/app/hooks/use-reload-confirmation.tsx
Dakshesh Jain 4f2b106852
fix: rich text editor (#1008)
* fix: undo/redo, placeholder overlapping with text, horizontal cursor

refractor: removed a lot of state-management that was not required

* fix: forwarding ref to remirror for getting extra helper functions

* fix: icon type error

* fix: value type not supported error on page block

* style: spacing, and UX for add link

---------

Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com>
2023-05-11 02:15:49 +05:30

29 lines
781 B
TypeScript

import { useCallback, useEffect, useState } from "react";
const useReloadConfirmations = (message?: string) => {
const [showAlert, setShowAlert] = useState(false);
const handleBeforeUnload = useCallback(
(event: BeforeUnloadEvent) => {
event.preventDefault();
event.returnValue = "";
return message ?? "Are you sure you want to leave?";
},
[message]
);
useEffect(() => {
if (!showAlert) {
window.removeEventListener("beforeunload", handleBeforeUnload);
return;
}
window.addEventListener("beforeunload", handleBeforeUnload);
return () => window.removeEventListener("beforeunload", handleBeforeUnload);
}, [handleBeforeUnload, showAlert]);
return { setShowAlert };
};
export default useReloadConfirmations;