Is it right way to use useWatch hook conditionally ? #9411
Unanswered
abdulmateentechbits
asked this question in
General
Replies: 1 comment
-
no, that's a rule of react custom hook. you can use the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Here I am using useWatch hook conditionally like bellow for an array value (cr_heads)
const crHeadArray = useWatch({ control, name: 'cr_heads' }) || [];
Why I am using it conditionally?
It's because of when useWatch can not watch that value has change it return undefined it cause and error when I use forEach loop over crHeadArray.
That's why I am using useWatch conditional if useWatch can not see any changes rather then return undefined it will return empty array so there were no issue in forEach loop
Beta Was this translation helpful? Give feedback.
All reactions