I think that, from a high level, I understand how it works, except there are one or two things that confuse me:
It would seem to be that React Hook Form retains its own state—that is, once you’ve registered a UI control with React Hook Form, it retains an internal reference to whatever state is created and associated with that control, and that control’s value may only then be accessed outside of React Hook Form by observing it via the watch utility. I want to say that the issue I’ve encountered with this is that the “watched” value can lag the actual user input to the field. For example, if I’ve entered “bike” into a field, as I did in one scenario, I found that the last observed value of the field ended up not being “bike” but rather “bik.” But this leads to another question—if I need to actually set some state associated with a given input registered with React Hook Form, should that state be based upon the “watched” value, or is there a way for me to instruct React Hook Form to use the local state (e.g., const [vehicle, setVehicle] = useState(‘bike’)) instead of its internal state?
Hopefully that makes sense.
submitted by /u/IanAbsentia
[link] [comments]