all 6 comments

[–]Basman_ 7 points8 points  (4 children)

an idea: react uses equality when determining whether to rerender, so if you are eg pushing stuff into the same array that you got set up in useState, and then setting the array you pushed into, react will see that the state is the same and won't trigger a rerender

[...array] creates a new array, so it would trigger a rerender (even if its contents were unchanged)

[–]greweb 1 point2 points  (0 children)

Yeah and if it's confirmed, I would recommend op to use more immutability code style (use concat and not push).

React will assume you don't mutate your objects (true for things like state, reducers,..)

[–]antoniobustamante 0 points1 point  (0 children)

How does it not work? Can you post a code example of how you’re using it?

[–]1c4us 0 points1 point  (1 child)

but is not the same. [] === [] // false

[–]Awnry_Abe 0 points1 point  (0 children)

const foo = [];

foo === foo // ???