Collaboration - How to show "unsaved changes" warning when unloading page #5216
Unanswered
julianpoy
asked this question in
Questions & Help
Replies: 1 comment 2 replies
-
For React: const [editorHasContent, setEditorHasContent] = useState<boolean>(false);
const editor = useEditor({
// ...
onTransaction: (event) => {
// Adapt if you need to check for different stuff (like Thumbnails)
const hasTextContent = event.editor.state.doc.textContent.trim().length > 0;
setEditorHasContent(hasContent);
}
});
useEffect(() => {
const handler = (event: BeforeUnloadEvent) => {
if (!editorHasContent || confirm('Are u sure?')) {
return;
}
event.preventDefault();
};
window.addEventListener('beforeunload', handler);
return () => {
window.removeEventListener('beforeunload', handler);
}
}, [hasUnsavedChanges]) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Using collaboration (Hocuspocus) --
In the event of a network/connection issue, if the user reloads the page prior to the connection failing, how do I present them with an unsaved changes warning so they don't lose their changes?
Beta Was this translation helpful? Give feedback.
All reactions