Calculated fields #8132
-
Hi there,
I want to be able to change
But Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 6 replies
-
Why are you recalculating and reseting in useEffect and that without a proper dependency array? Add subscription, values, recalc, reset in your dependency array and it won't go in infinite loop, the problem is with the implementation and not with RHF. |
Beta Was this translation helpful? Give feedback.
-
I have made Codesandbox in order to express my issue clearly. Thank you |
Beta Was this translation helpful? Give feedback.
-
Here's a working example based on your provided CSB. Check it out and see if it fits your use-case. Basically, instead of subscribing to the values update, you can |
Beta Was this translation helpful? Give feedback.
-
Thanks a ton @Moshyfawn , @ritikbanger ! It works perfectly. |
Beta Was this translation helpful? Give feedback.
-
Another way to avoid the infinite re-rendering is making sure discountPercent field value is not updated when value field changes. This will stop the re rendering |
Beta Was this translation helpful? Give feedback.
-
Hey guys, we have a zod schema that we pass to react-hook-form. Inside a refinement, we want to have access to a variable |
Beta Was this translation helpful? Give feedback.
Here's a working example based on your provided CSB.
Check it out and see if it fits your use-case.
Basically, instead of subscribing to the values update, you can
setValue
on the input'sonChange