Skip to content

Commit 0c9dcce

Browse files
authored
Warn users that resetting the form while passing values will also reset defaultValues
Added documentation that warns users that when calling `reset` with `values`, the form's `defaultValues` updates accordingly, which means subsequent calls to `reset` will use the previously passed `values` instead of the form's original `defaultValues`. This helps developers who call `reset` with API responses to be aware that subsequent `reset` only revert back to that API response
1 parent 07b728a commit 0c9dcce

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/content/docs/useform/reset.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Reset the entire form state, fields reference, and subscriptions. There are opti
2929

3030
<Admonition type="important" title="Rules">
3131

32-
- For controlled components you will need to pass `defaultValues` to `useForm` in order to `reset` the `Controller` components' value.
32+
- For controlled components you will need to pass `defaultValues` to `useForm` in order to `reset` the `Controller` components' value & and default value.
3333
- When `defaultValues` is not supplied to `reset` API, then HTML native [reset](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/reset) API will be invoked to restore the form.
3434
- Avoid calling `reset` before `useForm`'s `useEffect` is invoked, this is because `useForm`'s subscription needs to be ready before `reset` can send a signal to flush form state update.
3535
- It's recommended to `reset` inside `useEffect` after submission.
@@ -49,6 +49,7 @@ Reset the entire form state, fields reference, and subscriptions. There are opti
4949

5050
reset(undefined, { keepDirtyValues: true }) // reset other form state but keep defaultValues and form values
5151
```
52+
- Calling `reset` with `values` updates the form's `defaultValues` unless `options.keepDefaultValues` is set. If `reset` is later called without `values` or with `{}`, the form resets to the last `values` provided instead of the initial `defaultValues`
5253

5354
</Admonition>
5455

0 commit comments

Comments
 (0)