diff --git a/origin-src/components/Menu/MenuLinks.ts b/origin-src/components/Menu/MenuLinks.ts index 128025265..e7391d385 100644 --- a/origin-src/components/Menu/MenuLinks.ts +++ b/origin-src/components/Menu/MenuLinks.ts @@ -160,6 +160,10 @@ export const apiLinks: Pages = [ pathname: "/docs/useformstate/errormessage", name: "ErrorMessage", }, + { + pathname: "/docs/useformstate/formstatesubscribe", + name: "FormStateSubscribe", + }, ], }, { diff --git a/origin-src/content/docs/usecontroller/controller.mdx b/origin-src/content/docs/usecontroller/controller.mdx index 26e166dca..29435a86c 100644 --- a/origin-src/content/docs/usecontroller/controller.mdx +++ b/origin-src/content/docs/usecontroller/controller.mdx @@ -23,6 +23,7 @@ The following table contains information about the arguments for `Controller`. | `shouldUnregister` | boolean = false` | | Input will be unregistered after unmount and defaultValues will be removed as well.

**Note:** this prop should be avoided when using with `useFieldArray` as `unregister` function gets called after input unmount/remount and reorder. | | `disabled` | boolean = false` | | `disabled` prop will be returned from `field` prop. Controlled input will be disabled and its value will be omitted from the submission data. | | `defaultValue` | unknown | | **Important:** Can not apply `undefined` to `defaultValue` or `defaultValues` at `useForm`. | +| `exact` | boolean = false | | This prop will enable an exact match for input name subscriptions, default to true. | ### Return diff --git a/origin-src/content/docs/useformstate.mdx b/origin-src/content/docs/useformstate.mdx index ca24c84c3..b29e917ee 100644 --- a/origin-src/content/docs/useformstate.mdx +++ b/origin-src/content/docs/useformstate.mdx @@ -6,9 +6,13 @@ sidebar: apiLinks diff --git a/origin-src/content/docs/useformstate/formstatesubscribe.mdx b/origin-src/content/docs/useformstate/formstatesubscribe.mdx new file mode 100644 index 000000000..e2c8abe07 --- /dev/null +++ b/origin-src/content/docs/useformstate/formstatesubscribe.mdx @@ -0,0 +1,52 @@ +--- +title: FormStateSubscribe +description: Component to subscribe to form state update +sidebar: apiLinks +--- + +## \ `FormStateSubscribe:` Component + +A React Hook Form component that provides the same functionality as `uesFormState`, but in component form. Instead of using the hook inside another component, you can use `` directly in your JSX to subscribe to and render form state. + +### Props + +--- + +| Name | Type | Description | +| ---------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `control` | Object | [`control`](/docs/useform/control) object provided by `useForm`. It's optional if you are using `FormProvider`. | +| `name` | string \| string[] | Provide a single input name, an array of them, or subscribe to all inputs' formState update. | +| `disabled` | boolean = false | Option to disable the subscription. | +| `exact` | boolean = false | This prop will enable an exact match for input name subscriptions. | +| `render` | Function | Subscribes to form state of specified form field(s) and re-renders its child function whenever the form state changes. This allows you to declaratively consume form state in JSX without manually wiring up state. | + +**Examples:** + +--- + +```tsx copy sandbox="" +import { useForm, FormStateSubscribe } from "react-hook-form" + +const App = () => { + const { register, control } = useForm() + + return ( +
+
+ + + {/* re-render only when form state of `foo` changes */} + {errors.foo?.message}} + /> + +
+ ) +} +``` + +``` + +``` diff --git a/origin-src/content/docs/usewatch.mdx b/origin-src/content/docs/usewatch.mdx index ed5163f17..3f1d02cd8 100644 --- a/origin-src/content/docs/usewatch.mdx +++ b/origin-src/content/docs/usewatch.mdx @@ -4,6 +4,15 @@ description: React Hook for subscribing to input changes sidebar: apiLinks --- + + ## \ `useWatch:` `({ control?: Control, name?: string, defaultValue?: unknown, disabled?: boolean }) => object` Behaves similarly to the `watch` API, however, this will isolate re-rendering at the custom hook level and potentially result in better performance for your application. diff --git a/origin-src/data/api.tsx b/origin-src/data/api.tsx index b2c6acf70..b35e15841 100644 --- a/origin-src/data/api.tsx +++ b/origin-src/data/api.tsx @@ -2843,6 +2843,20 @@ setValue('notRegisteredInput', { test: '1', test2: '2' }); // ✅ sugar syntax t + + + exact + + + boolean = false + + + +

+ This prop will enable an exact match for input name subscriptions, default to true. +

+ + ), tips: (