Skip to content

why array extension method causes redux error: state mutation #4758

Answered by phryneas
kianooshsanatkar asked this question in Help
Discussion options

You must be logged in to vote

I have to be honest, i didn't know that people were still modifying built-in protoypes.
That's widely considered a bad practice for about a decade at this point, I would really recommend that you don't do that - it will cause all kinds of weird behaviour since none of your dependencies expect that.

As for Redux Toolkit itself, we require you to use plain objects and plain arrays in state. You fascinatingly found a way here to make arrays "not plain" anymore.
I don't know if we can help you with that :/

I would recommend you do something like arrayAny(arr, condition) instead - or in this case, just use Array.prototype.some which already exists.

PS: Your implementation is also way slower than

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kianooshsanatkar
Comment options

Answer selected by kianooshsanatkar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants