-
Issue Here I am providing the link for your reference. CodeSandBox Reference Here if you see I am trying to clear and disable the textfield whenever the checkbox is enabled. The same thing I tried using normal react useState and useEffect , there It is working fine . It seems like there is some issue with the react hook form. Please provide your valuable input to resolve this issue. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You codesandbox url is using react-hook-form version 3.21.18 which is very old and not supported any more. Please try to upgrade react-hook-form to make sure it's compatible with new form handling. |
Beta Was this translation helpful? Give feedback.
@ViCkY-29
The root cause is from MUI TextField component because its parent wrapper FormControl component will handle filled or empty value state (the one that shows label animation on UI) by using onChange callback or watch on change of value on TextField component. While
setValue
from react-hook-form cannot mutate inner locale state of the component, you need to trigger it manually.Luckily, MUI is using FormControlProvider to manage filled or empty value state via function
onFilled
oronEmpty
, you can access those methods viauseFormControl()
hook to trigger change UI state manually.Workaround: https://codesandbox.io/s/react-hook-form-mui-textfield-forked-dhdlh8?file=/src/index.js