javascript icon indicating copy to clipboard operation
javascript copied to clipboard

Ignore property modifications on params named "state"

Open openjck opened this issue 4 years ago • 3 comments

The no-param-reassign rule allows property modifications for params with certain names, like acc and response. I would like to suggest that state is also allowed, for users of Redux Toolkit. The Redux Toolkit documentation recommends this.

openjck avatar Oct 21 '21 22:10 openjck

state.push isn't reassignment; it's only state.x = mutation that seems like you're asking for?

https://redux-toolkit.js.org/usage/immer-reducers#resetting-and-replacing-state suggests that state = is actually a huge footgun and antipattern. I'm not sure it's worth it to have this in the default config, considering you can override/extend the rule config yourself to allow it.

ljharb avatar Oct 21 '21 22:10 ljharb

Yep, it's only the state.x = pattern that I'm referring to. I've updated the description to be more clear.

openjck avatar Oct 21 '21 22:10 openjck

If there was a way to prevent reassignment but allow mutation, that'd be worth considering, but i believe the rule doesn't offer that level of granularity.

ljharb avatar Oct 21 '21 22:10 ljharb