Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Fix(useForm): update "defaultValues" by "reset(nextValues)"
Browse files Browse the repository at this point in the history
  • Loading branch information
wellyshen committed Dec 25, 2020
1 parent 0353e40 commit f6b97a2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-yaks-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-cool-form": patch
---

Fix(useForm): update `defaultValues` by `reset(nextValues)`
2 changes: 1 addition & 1 deletion app/src/Playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Playground = (): JSX.Element => {
onSubmit: (values) => console.log("LOG ===> onSubmit: ", values),
onError: (errors) => console.log("LOG ===> onError: ", errors),
});
console.log("LOG ===> ", getState("dirtyFields"));
console.log("LOG ===> ", getState(["isDirty", "dirtyFields"]));

useEffect(() => {
reset({
Expand Down
11 changes: 8 additions & 3 deletions src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,14 @@ export default <V extends FormValues = FormValues>({
if (skip[key]) return;

if (key === "values") {
values =
(isFunction(values) ? values(stateRef.current.values) : values) ||
initialStateRef.current.values;
if (!values) {
values = initialStateRef.current.values;
} else {
values = isFunction(values)
? values(stateRef.current.values)
: values;
initialStateRef.current.values = values;
}

state[key] = values;
setNodesOrStateValue(values);
Expand Down

0 comments on commit f6b97a2

Please sign in to comment.