</> Watch: Component
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. |
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 | default value for useWatch to return before the initial render.Note: the first render will always return defaultValue when it's supplied. |
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 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}names={["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 to star and support it.