From 0c9dcce6f8e73f168fc87565046adf00b992ab23 Mon Sep 17 00:00:00 2001 From: Davin <38467854+shaundavin13@users.noreply.github.com> Date: Thu, 20 Mar 2025 14:22:15 +0700 Subject: [PATCH 1/3] 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 --- src/content/docs/useform/reset.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/content/docs/useform/reset.mdx b/src/content/docs/useform/reset.mdx index 90e0c74b7..4d73fcc77 100644 --- a/src/content/docs/useform/reset.mdx +++ b/src/content/docs/useform/reset.mdx @@ -29,7 +29,7 @@ Reset the entire form state, fields reference, and subscriptions. There are opti -- For controlled components you will need to pass `defaultValues` to `useForm` in order to `reset` the `Controller` components' value. +- For controlled components you will need to pass `defaultValues` to `useForm` in order to `reset` the `Controller` components' value & and default value. - 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. - 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. - 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 reset(undefined, { keepDirtyValues: true }) // reset other form state but keep defaultValues and form values ``` +- 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` From 08c726452a54b19559a021f538f43826c4908ddf Mon Sep 17 00:00:00 2001 From: Davin <38467854+shaundavin13@users.noreply.github.com> Date: Thu, 20 Mar 2025 14:28:13 +0700 Subject: [PATCH 2/3] Remove superfluous phrase added in previous commit --- src/content/docs/useform/reset.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/useform/reset.mdx b/src/content/docs/useform/reset.mdx index 4d73fcc77..29fadb2d5 100644 --- a/src/content/docs/useform/reset.mdx +++ b/src/content/docs/useform/reset.mdx @@ -29,7 +29,7 @@ Reset the entire form state, fields reference, and subscriptions. There are opti -- For controlled components you will need to pass `defaultValues` to `useForm` in order to `reset` the `Controller` components' value & and default value. +- For controlled components you will need to pass `defaultValues` to `useForm` in order to `reset` the `Controller` components' value - 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. - 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. - It's recommended to `reset` inside `useEffect` after submission. From 82565ec78d1226a0743b3f9930186eed6a8c389b Mon Sep 17 00:00:00 2001 From: Davin <38467854+shaundavin13@users.noreply.github.com> Date: Thu, 20 Mar 2025 14:29:12 +0700 Subject: [PATCH 3/3] Add back missing period --- src/content/docs/useform/reset.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/useform/reset.mdx b/src/content/docs/useform/reset.mdx index 29fadb2d5..3b8c0ebd0 100644 --- a/src/content/docs/useform/reset.mdx +++ b/src/content/docs/useform/reset.mdx @@ -29,7 +29,7 @@ Reset the entire form state, fields reference, and subscriptions. There are opti -- For controlled components you will need to pass `defaultValues` to `useForm` in order to `reset` the `Controller` components' value +- For controlled components you will need to pass `defaultValues` to `useForm` in order to `reset` the `Controller` components' value. - 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. - 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. - It's recommended to `reset` inside `useEffect` after submission.