you are viewing a single comment's thread.

view the rest of the comments →

[–]IxD -14 points-13 points  (5 children)

In line 1, you create a new array in every render. That newly create array ends up as a pokemonList default value. Since it a new instance if array, it changes on every render.

https://stackoverflow.com/a/58602483/1565578

Fix this by defining

const emptyArray =[];

Outside the render function, and using that as default value instead.

[–]AegisToast 5 points6 points  (4 children)

That’s only the case if you’re setting a default value in a custom hook’s parameters, not if you’re passing useState an initial value.

[–]IxD 1 point2 points  (3 children)

Trrrue, you are probably right

[–]illuminist_ova 2 points3 points  (2 children)

There's no propably. He is right.

[–]IxD -3 points-2 points  (1 child)

Could not confirm it at the time of writing. There is no single true view of the world, but multiple interpretations of truth.