DEV Community


Discussion on: Don't over useState

tkdodo profile image
Dominik D Author

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:

const categories = React.useMemo(
  () => data ? computeCategories(data) : [],
Enter fullscreen mode Exit fullscreen mode

and now we call that function the same amount of times as before.