Context provider that handles unsaved changes with toasts, drawers, and modals.
Edit the form, then navigate away. Toast appears on desktop, drawer on mobile, modal for page navigation.
Bottom center floating toast
Slides up from bottom
Confirmation for cross-page
You have unsaved changes that will be lost if you leave this page. Would you like to save before leaving?
beforeunloadnpx shadcn@latest add https://raw.githubusercontent.com/gluer-space/unsave-provider/main/public/r/registry.jsoncp components/unsave-provider.tsx your-project/<UnsavedChangesProvider>
{children}
</UnsavedChangesProvider>const { setDirty, isDirty } = useUnsavedChanges({
onSave: async () => { await save(); },
onCancel: () => { reset(); },
});
onChange={() => setDirty(true)}Try it out
Navigate to /about to see it work on another page.