File tree 1 file changed +5
-4
lines changed
packages/react-hook-form/src/useForm
1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -128,6 +128,7 @@ export const useForm = <
128
128
watch,
129
129
setValue,
130
130
getValues,
131
+ formState,
131
132
handleSubmit : handleSubmitReactHookForm ,
132
133
setError,
133
134
} = useHookFormResult ;
@@ -229,11 +230,11 @@ export const useForm = <
229
230
return ( ) => subscription . unsubscribe ( ) ;
230
231
} , [ watch ] ) ;
231
232
232
- const onValuesChange = ( changeValues : TVariables ) => {
233
- if ( warnWhenUnsavedChanges ) {
234
- setWarnWhen ( true ) ;
235
- }
233
+ useEffect ( ( ) => {
234
+ setWarnWhen ( formState . isDirty && warnWhenUnsavedChanges ) ;
235
+ } , [ formState . isDirty , warnWhenUnsavedChanges ] ) ;
236
236
237
+ const onValuesChange = ( changeValues : TVariables ) => {
237
238
if ( refineCoreProps ?. autoSave ?. enabled ) {
238
239
setWarnWhen ( false ) ;
239
240
You can’t perform that action at this time.
0 commit comments