diff --git a/.changeset/ten-yaks-reflect.md b/.changeset/ten-yaks-reflect.md new file mode 100644 index 00000000..e3634071 --- /dev/null +++ b/.changeset/ten-yaks-reflect.md @@ -0,0 +1,5 @@ +--- +"react-cool-form": patch +--- + +Fix(useForm): update `defaultValues` by `reset(nextValues)` diff --git a/app/src/Playground/index.tsx b/app/src/Playground/index.tsx index 5283af77..dd07d77a 100644 --- a/app/src/Playground/index.tsx +++ b/app/src/Playground/index.tsx @@ -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({ diff --git a/src/useForm.ts b/src/useForm.ts index c7b769c7..e676de90 100644 --- a/src/useForm.ts +++ b/src/useForm.ts @@ -681,9 +681,14 @@ export default ({ 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);