Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-dryers-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@refinedev/react-hook-form": patch
---

fix(react-hook-form): properly warn unsaved changes only when there are actual changes (#6691)
9 changes: 5 additions & 4 deletions packages/react-hook-form/src/useForm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const useForm = <
watch,
setValue,
getValues,
formState,
handleSubmit: handleSubmitReactHookForm,
setError,
} = useHookFormResult;
Expand Down Expand Up @@ -229,11 +230,11 @@ export const useForm = <
return () => subscription.unsubscribe();
}, [watch]);

const onValuesChange = (changeValues: TVariables) => {
if (warnWhenUnsavedChanges) {
setWarnWhen(true);
}
useEffect(() => {
setWarnWhen(formState.isDirty && warnWhenUnsavedChanges);
}, [formState.isDirty, warnWhenUnsavedChanges]);

const onValuesChange = (changeValues: TVariables) => {
if (refineCoreProps?.autoSave?.enabled) {
setWarnWhen(false);

Expand Down