You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{useEffect,memo}from'react'import{useForm,useWatch}from"react-hook-form755"// v7.55.0, behavior changedconstdefaultName={label: 'default label'}constdefaultValues={name: defaultName}functionApp(){const{ register, handleSubmit, control }=useForm({
defaultValues,});return(<div><div><h1>react-hook-form <b>v7.55.0</b></h1><formonSubmit={handleSubmit(data=>console.log("==== onSubmit called ====",data),console.error)}><input{...register("name")}/><buttontype="submit">Submit</button></form></div><OtherFieldcontrol={control}/></div>)}constOtherField=memo(({ control })=>{// !! useWatch will fire and return new Reference Object when Submit clickedconstwatchName=useWatch({ control,name: "name"});console.log("==== useWatch triggered ====: ",watchName===defaultName);useEffect(()=>{console.log("==== useEffect triggered ====");// resetField('OtherFieldName')},[watchName]);returnnull})exportdefaultApp
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi folks
I notice, since
v7.55 (~ v7.62.0)
,useWatch
behavior has changedWhen watching an Object, calling
handleSubmit
now triggersuseWatch
—something that didn’t happen inv7.54.2
.Is this an intentional breaking change or a bug?
I’ve seen some discussion and PR ( #12945 ), but the same issue still exists in
v7.62.0
.Here is reproduction repo. sample code and screenshots are shown below.
Demo repo: https://github.com/flameddd/react-hook-form-useWatch_issue
code: https://github.com/flameddd/react-hook-form-useWatch_issue/blob/main/src/App.jsx
v7.55.0 when click Submit button
v7.62.0 when click Submit button
v7.54.2 when click Submit button
Thank
react-hook-form
so much !!!Beta Was this translation helpful? Give feedback.
All reactions