Skip to content

Why doesnt registering to a field within an object that is itself registered not cause the other controller to render? #10023

Answered by leapful
paulleonartcalvo asked this question in Q&A
Discussion options

You must be logged in to vote

@paulleonartcalvo

Component Controller and also the whole react-hook-form are built with optimization for re-rendering therefore when registering a form field name, it will be treated as an isolated standalone field to prevent side effect with other registered fields. So yes, your implementation cannot work properly following your expected behavior.

The correct way to solve this problem is to register field config.name and config.colors then perform update on each other field if needed by using setValue method.

For example:

// Field "config.name"
const onChange = (data) => {
   field.onChange(data.name);
   setValue('config.colors', data.colors);
   trigger('config.colors') // trigger val…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by paulleonartcalvo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants