{"repo":"rl0425/use-form-guard","free":true,"listed":false,"github":"https://github.com/rl0425/use-form-guard","clone":"git clone https://github.com/rl0425/use-form-guard.git","description":"Framework-agnostic React hook to prevent accidental navigation with unsaved form changes. Works with Next.js App Router, React Hook Form, Formik, and more.","language":"TypeScript","stars":49,"topics":["form","navigation-guard","nextjs","nextjs-app-router","react","react-hook-form","react-hooks","typescript"],"license":"MIT","category":"saas-starters-boilerplates","readme_excerpt":"use-form-guard Framework-agnostic React hook to prevent accidental navigation when a form has unsaved changes. Works with React Hook Form, Formik, TanStack Form, or any boolean dirty state. Covers browser tab close, SPA navigation, and the browser back/forward button — including Next.js App Router . --- The Problem Every form-heavy app needs this pattern: React Hook Form gives you formState.isDirty , but it does not handle: - Browser tab close / refresh ( beforeunload ) - SPA navigation ( router.push() , clicks) - The browser back / forward button ( popstate ) Next.js App Router made this especially painful by removing the router.events API that Pages Router developers relied on. There is no official solution — developers have been copy-pasting 30+ line hacks in every project. use-form-guard solves all of this in one hook. --- Features - Zero dependencies — only requires React ≥ 17 as a peer - Framework-agnostic — works with React Hook Form, Formik, TanStack Form, useState , anything - Covers all exit paths — tab close, SPA navigation, back/forward button - Next.js App Router support — patches history.pushState to intercept clicks and router.push() - Custom dialog support — bring your own modal instead of the native window.confirm() - TypeScript-first — full type inference, no @types/ needed - Tiny — 1.75 KB minified ( 0.8 KB gzipped) --- Installation --- Usage With React Hook Form With useState (or any boolean) With Formik With a custom dialog (no window.confirm ) With a cus","default_branch":null,"files":null,"tree":[],"storefront":"/r/rl0425","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/rl0425/use-form-guard/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}