Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

FormResetOptions.md

54 lines1.6 KB

1---
2id: FormResetOptions
3title: FormResetOptions
4---
5​
6Defined in: [FormApi/FormApi.public.ts:554](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi/FormApi.public.ts#L554)
7​
8Options controlling whether `reset(values)` replaces the default-value
9baseline.
10​
11## Example
12​
13```ts
14formApi.reset(savedValues, { updateDefaultValues: false })
15```
16​
17## Properties
18​
19### updateDefaultValues?
20​
21```ts
22optional updateDefaultValues?: boolean;
23```
24​
25Defined in: [FormApi/FormApi.public.ts:584](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi/FormApi.public.ts#L584)
26​
27Whether `reset(values)` should also update the form's `defaultValues`
28baseline.
29​
30By default, passing values to `reset` treats those values as the new reset
31baseline. Future `reset()` calls will return to those values, and
32`state.isDefaultValue` will compare against them.
33​
34Set this to `false` when you want reset semantics for form state
35(clearing touched, dirty, validation, submission state, and mounted fields)
36but want to keep comparing against the previous `defaultValues`.
37​
38With `updateDefaultValues: false`, `state.isDirty` is reset to `false`,
39but `state.isDefaultValue` may be `false` if the provided reset values do
40not deeply equal the preserved defaults.
41​
42This option is ignored when no reset values are provided.
43​
44#### Example
45​
46```ts
47const originalDefaults = formApi.defaultValues
48​
49formApi.reset(savedDraft, { updateDefaultValues: false })
50// `savedDraft` is current, but `originalDefaults` remains the baseline.
51​
52formApi.reset()
53// Restores `originalDefaults`, not `savedDraft`.
54```