Skip to content

Commit 237f4ab

Browse files
committed
Do not reset values on useForm state change, because this can cause confusion
1 parent 3696ff3 commit 237f4ab

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@
1616
1717
form.setError("email", ...); // Must be "error-email" | "error-password"
1818
```
19+
20+
# 1.2.9 (03/04/2021)
21+
22+
- Do not reset values on useForm state change, because this can cause confusion.

src/hooks.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DefaultState, DefaultError, FormState, ChildFormState, Validator } from
44
/**
55
* Creates a new root form.
66
* This hook doesn't cause a rerender.
7-
* @param defaultValues The default values for this form.
7+
* @param defaultValues The default values for this form. When this value changes, nothing happens, use useEffect() with form.setValues to set form values on state change.
88
* @param validator The validator to use, optional.
99
* @param validateOnChange Validate on change? Optional, default is false.
1010
* @param validateOnMount Validate on mount? Optional, default is false.
@@ -30,9 +30,10 @@ export function useForm<T, State = DefaultState, Error extends string = DefaultE
3030
);
3131
}
3232

33-
useEffect(() => {
34-
c.current!.setDefaultValues(defaultValues, c.current!.validateOnMount, true, false);
35-
}, [defaultValues]);
33+
// Do not reset values on state change
34+
// useEffect(() => {
35+
// c.current!.setDefaultValues(defaultValues, c.current!.validateOnMount, true, false);
36+
// }, [defaultValues]);
3637

3738
return c.current;
3839
}

0 commit comments

Comments
 (0)