In my functional component, I want to memorize some value which depends on Id
property of an object:
obj={
innerProperty:{
id:1
}
}
useMemo(()=>someComplaxFunction(), [obj.innerProperty.id])
I want to do something like this, but the issue is, innerProperty
can be undefined
. So I need to add a check for innerProperty, but I cannot add that outside useMemo
as it gives me error that hooks should not be called conditionally and not even inside as then I will have to add obj
as dependency which I don't want because other properties may change.
Need to know how can I achieve this. Any help is appreciated.
Thanks in advance!