Jul 7, 2023
I fear this misses the primary reason to use useMemo: to prevent dependency updates.
It is rare that a calculation is expensive enough to worry about rerunning it. I see a lot of premature optimization when people use useMemo for this.
But when you need a constructed object, or a filtered/mapped array, to be used in an effect, useMemo is vital. Otherwise you rerun the effect on every render, whether you meant to or not.
98% of the time, I'm stabilizing dependency arrays, not worrying about calculation times.