</> Watch: WatchProps Since v7.65.0
A React Hook Form component that provides the same functionality as useWatch, but in component form. Instead of using the hook inside another component, you can use <Watch /> directly in your JSX to subscribe to and render form values.
Props
| Name | Type | Description |
|---|---|---|
name | string | string[] | undefined | Name of the field(s) to subscribe to. (The deprecated names prop is still accepted for backwards compatibility, but will be removed in a future major version — use name instead.) |
control | Object | control object provided by useForm. It's optional if you are using FormProvider. |
compute | function | Subscribe to selective and computed form values.
|
defaultValue | unknown | Fallback value returned before the form has mounted and no current value exists yet. Once the form is mounted, the actual current form value takes precedence over this fallback. |
disabled | boolean = false | Option to disable the subscription. |
exact | boolean = false | Enable exact name matching. When false (default), the subscription fires when the subscribed name is a prefix of the changed field name, or vice versa. Since v7.81.0 When true, it fires when the subscribed field itself or one of its ancestor paths is updated, but not when a nested child path changes. See useWatch for details. |
render | Function | Subscribes to specified form field(s) and re-renders its child function whenever the values change. This allows you to declaratively consume form values in JSX without manually wiring up state. |
Examples:
import { useForm, Watch } from "react-hook-form"const App = () => {const { register, control } = useForm()return (<div><form><input {...register("foo")} /><input {...register("bar")} /></form>{/* re-render only when value of `foo` changes */}<Watchcontrol={control}name={["foo"]}render={([foo]) => <span>{foo}</span>}/></div>)}
Thank you for your support
If you find React Hook Form to be useful in your project, please consider starring and supporting it.