We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 93b4743 commit f4260a6Copy full SHA for f4260a6
app/(admin)/me/_components/form.tsx
@@ -31,11 +31,10 @@ export function MeForm() {
31
});
32
33
useEffect(() => {
34
+ if (!form.formState.isDirty) return;
35
const message = "您有尚未儲存的更動。確定要關閉而不儲存嗎?您的更動將會遺失。";
36
37
const handleBeforeUnload = (e: BeforeUnloadEvent) => {
- if (!form.formState.isDirty) return;
38
-
39
e.preventDefault();
40
e.returnValue = message;
41
return message;
@@ -46,7 +45,7 @@ export function MeForm() {
46
45
return () => {
47
window.removeEventListener("beforeunload", handleBeforeUnload);
48
};
49
- }, [form]);
+ }, [form.formState.isDirty]);
50
51
const avatar = form.watch("avatar");
52
0 commit comments