You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* (watch): make first half reflect overloads
* (watch): make examples heading real heading in html
* Update watch.mdx
---------
Co-authored-by: Beier (Bill) <[email protected]>
|`callback`| <TypeText>`(data, { name, type }) => void`</TypeText> | callback function to subscribe to all fields changes |
87
+
|`defaultValues`| <TypeText>`{[key:string]: unknown}`</TypeText> |_optional_. defaultValues for the entire form |
88
+
89
+
**Returns** object with `unsubscribe` function.
90
+
91
+
```tsx
92
+
useEffect(() => {
93
+
const { unsubscribe } =watch((value) => {
94
+
console.log(value)
95
+
})
96
+
return () =>unsubscribe()
97
+
}, [watch])
98
+
```
99
+
100
+
### Rules
101
+
102
+
---
34
103
35
104
- When `defaultValue` is not defined, the first render of `watch` will return `undefined` because it is called before `register`. It's **recommended** to provide `defaultValues` at `useForm` to avoid this behaviour, but you can set the inline `defaultValue` as the second argument.
36
105
- When both `defaultValue` and `defaultValues` are supplied, `defaultValue` will be returned.
37
106
- This API will trigger re-render at the root of your app or form, consider using a callback or the [useWatch](/docs/usewatch) api if you are experiencing performance issues.
38
107
-`watch` result is optimised for render phase instead of `useEffect`'s deps, to detect value update you may want to use an external custom hook for value comparison.
0 commit comments