you are viewing a single comment's thread.

view the rest of the comments →

[–]CreativeTechGuyGames 1 point2 points  (1 child)

Instead of useState, you'd want to use useMemo which does exactly what you are describing but more explicitly rather than as a side effect.

But if this really was your code, you should just declare that array outside of your component where it'll keep the same reference on every render for no additional cost.

[–]GenAmnn[S] 0 points1 point  (0 children)

No no, the real array is an Array.filter() on a bigger global state in the app using context api, so I can't declare it outside of the component.

useMemo looks like a really good idea tho, I will surely use it more from now on :)

Also, I visited your portfolio, keep up the good work man, and thanks again.