Jun 21, 2023
The problem is actually that you used useEffect and setState when you could have and should have used useMemo (as you did in the second example). Whether you do that inside or outside your component doesn't matter--it's doing it the correct way that's important.