I have a question regarding React\'s shouldComponentUpdate (when not overwritten). I do prefer pure, function components, but I am afraid that it updates every
Another approach is to use useMemo to update values only when watched ones are updated:
const memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]);
In case of objects there's an option of using state hook to cache the value of interested variable, after making sure it's updated. Eg by using lodash:
const [fooCached, setFooCached]: any = useState(null);
if (!_.isEqual(fooCached, foo)) {
setFooCached(foo);
}`).
const showFoo = useMemo(() => {
return Foo name: { foo.name }
}, [fooCached]);