What we do is calling computeCategories in every render, which we didn’t do before. This doesn’t matter unless this function is expensive. If we have proof that we need to optimize it, we can do:
computeCategories
const categories = React.useMemo( () => data ? computeCategories(data) : [], [data] )
and now we call that function the same amount of times as before.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
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.
What we do is calling
computeCategories
in every render, which we didn’t do before. This doesn’t matter unless this function is expensive. If we have proof that we need to optimize it, we can do:and now we call that function the same amount of times as before.