The summation function here is so simple. But consider you are making an expensive operation instead of just sum.In that case if you already have a cached value from previous call it becomes handy.
Even react.memo should be doing something similar to this(But handling all limitations which my solution had)
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.