Skip to content

Commit 88a45ec

Browse files
committed
fix: useForm - dirtyFields and touchedFields logic fix
1 parent d2b6f29 commit 88a45ec

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Shared/Hooks/useForm/useForm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const useForm = <T extends Record<keyof T, any> = {}>(options?: {
5151
[key]: value,
5252
})
5353
const initialValues: Partial<T> = options?.initialValues ?? {}
54-
setDirtyFields({ ...dirtyFields, [key]: initialValues[key] === data[key] })
54+
setDirtyFields({ ...dirtyFields, [key]: initialValues[key] !== value })
5555

5656
const validationMode = options?.validationMode ?? 'onChange'
5757
if (validationMode === 'onChange' || enableValidationOnChange[key] || errors[key]) {
@@ -90,7 +90,7 @@ export const useForm = <T extends Record<keyof T, any> = {}>(options?: {
9090
*/
9191
const onFocus = (key: keyof T) => () => {
9292
setTouchedFields({
93-
...data,
93+
...touchedFields,
9494
[key]: true,
9595
})
9696
}

0 commit comments

Comments
 (0)