-
Version Number7.25.0 Codesandbox/Expo snackhttps://codesandbox.io/s/react-hook-form-js-forked-lbhoo?file=/src/App.js Steps to reproduce
Expected behaviourCalling setValue from an effect should update useWatch values. What browsers are you seeing the problem on?No response Relevant log outputNo response Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
Consider lifting
setValue('test', 'data');
useWatch({ name: 'test' }); // ❌ subscription is happened after value update, no update received
useWatch({ name: 'example' }); // ✅ input value update will be received and trigger re-render
setValue('example', 'data'); |
Beta Was this translation helpful? Give feedback.
-
thanks @Moshyfawn! that's correct. you are truly an expert on this lib. |
Beta Was this translation helpful? Give feedback.
-
Okay, |
Beta Was this translation helpful? Give feedback.
-
Not necessarily. Just make sure |
Beta Was this translation helpful? Give feedback.
-
The codesandbox is updated to show a different case https://codesandbox.io/s/react-hook-form-js-forked-lbhoo?file=/src/App.js
|
Beta Was this translation helpful? Give feedback.
-
Is there any eslint rule that could prevent this? |
Beta Was this translation helpful? Give feedback.
Consider lifting
setValue
out of the child or switch the order of<ComponentA />
and<ComponentB />
around, so that the component usinguseWatch
is before thesetValue
call. It's the expected behavior. See Rules section of RHF useWatch docs section: