You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
removeAllBears: ()=>set((state)=>{// Using slice to create a new array without the last item// The current array (state.bears) is not modifed// Instead a shallow copy is made, and new state with new array is returnedconstnewArray=state.bears.slice(0,-1);return{bears: newArray};}),
If you do want to use mutating methods, you should use something like immer. But i wouldn't use this unless you need to do more complex stuff like modifying a value thats deeply nested into multiple objects.
@charkour
Adding a simple demo for reproducing the issue.
[{id:1},{id:2},{id:3}]
[{id:1},{id:2}]
Expected result -
[{id:1},{id:2},{id:3}]
Actual result -
[{id:1},{id:2}]
The text was updated successfully, but these errors were encountered: