It's a fine solution if the object property always exists however if the property is not present at some point you get a reference error. My workaround in this scenario is to check if prop exists inside the hook
useEffect(()=> {
if (values?.age) {
ageChangeSideEffect(values.age);
}
}, [values])
There is no change listening in values because it's an object which is checked for equality by reference. If values is passed to the component as a property and its value is composed as a plain inline object, it will be a new value on each render.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
It's a fine solution if the object property always exists however if the property is not present at some point you get a reference error. My workaround in this scenario is to check if prop exists inside the hook
useEffect(()=> {
if (values?.age) {
ageChangeSideEffect(values.age);
}
}, [values])
I think is better to use values?.age as a dependency, to avoid to listen all changes in values.
There is no change listening in
values
because it's an object which is checked for equality by reference. Ifvalues
is passed to the component as a property and its value is composed as a plain inline object, it will be a new value on each render.