Skip to content

Commit 3828000

Browse files
authored
Merge pull request #3038 from Luk-z/patch-1
2 parents ae59d5f + 5edbbc9 commit 3828000

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

docs/usage/immer-reducers.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,21 @@ const itemsSlice = createSlice({
453453

454454
Many ESLint configs include the https://eslint.org/docs/rules/no-param-reassign rule, which may also warn about mutations to nested fields. That can cause the rule to warn about mutations to `state` in Immer-powered reducers, which is not helpful.
455455

456-
To resolve this, you can tell the ESLint rule to ignore mutations to a parameter named `state`:
456+
To resolve this, you can tell the ESLint rule to ignore mutations and assignment to a parameter named `state` only in slice files:
457457

458458
```js
459-
{
460-
'no-param-reassign': ['error', { props: true, ignorePropertyModificationsFor: ['state'] }]
459+
// @filename .eslintrc.js
460+
module.exports = {
461+
// add to your ESLint config definition
462+
overrides: [
463+
{
464+
// feel free to replace with your preferred file pattern - eg. 'src/**/*Slice.ts'
465+
files: ['src/**/*.slice.ts'],
466+
// avoid state param assignment
467+
rules: { 'no-param-reassign': ['error', { props: false }] },
468+
},
469+
],
461470
}
462-
463471
```
464472

465473
## Why Immer is Built In

0 commit comments

Comments
 (0)