Hi folksI notice, since When watching an Object, calling Is this an intentional breaking change or a bug? I’ve seen some discussion and PR ( #12945 ), but the same issue still exists in 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 import { useEffect, memo } from 'react'
import { useForm, useWatch } from "react-hook-form755" // v7.55.0, behavior changed
const defaultName = { label: 'default label' }
const defaultValues = { name: defaultName }
function App() {
const { register, handleSubmit, control } = useForm({
defaultValues,
});
return (
<div>
<div>
<h1>react-hook-form <b>v7.55.0</b></h1>
<form onSubmit={handleSubmit(
data => console.log("==== onSubmit called ====", data),
console.error
)}>
<input {...register("name")} />
<button type="submit">Submit</button>
</form>
</div>
<OtherField control={control} />
</div>
)
}
const OtherField = memo(({ control }) => {
// !! useWatch will fire and return new Reference Object when Submit clicked
const watchName = useWatch({ control, name: "name" });
console.log("==== useWatch triggered ====: ", watchName === defaultName);
useEffect(() => {
console.log("==== useEffect triggered ====");
// resetField('OtherFieldName')
}, [watchName]);
return null
})
export default Appv7.55.0 when click Submit buttonv7.62.0 when click Submit buttonv7.54.2 when click Submit buttonThank
|
Replies: 1 comment
|
Yes, it changed, and it was a bug. It's fixed in 7.75.0. 7.55.0 merged Object.keys(formState).length >= Object.keys(_proxyFormState).length
Your repro, memo'd child, one click on Submit, child render count before and after: One aside on the log line itself: |



Yes, it changed, and it was a bug. It's fixed in 7.75.0.
7.55.0 merged
_subjects.valuesinto_subjects.state, andshouldRenderFormStatehad a size check that let any state emission reach a subscriber with the same number of subscribed keys:handleSubmitemits three state updates and none of them carry avalueskey.{ isSubmitting: true }is one key,useWatchsubscribes with{ values: true }, also one key, so1 >= 1passed with zero key overlap. #13398 put that branch behindisRoot, so only the rootuseFormsubscriber gets it now.Your repro, memo'd child, one click on Submit, child render count before and after: