Skip to content

Commit

Permalink
refactor: minor reset values simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Nov 13, 2022
1 parent 90b61fc commit 31b4775
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions packages/vee-validate/src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,16 +495,10 @@ export function useForm<TValues extends Record<string, any> = Record<string, any
// Reset all field states first
mutateAllFields(f => f.resetField());

// set initial values if provided
if (state?.values) {
setInitialValues(state.values);
setValues(state?.values);
} else {
// clean up the initial values back to the original
setInitialValues(originalInitialValues.value);
// otherwise clean the current values
setValues(originalInitialValues.value);
}
// reset values
const newValues = state?.values ? state.values : originalInitialValues.value;
setInitialValues(newValues);
setValues(newValues);

if (state?.touched) {
setTouched(state.touched);
Expand Down

0 comments on commit 31b4775

Please sign in to comment.