Skip to content

Commit

Permalink
Add default prop doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Secretmapper committed Jul 6, 2019
1 parent 1c757d5 commit e5ebca9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,35 @@ function* handleImmerReducerAction(action: Actions<typeof MyImmerReducer>) {
}
```

**Warning:** Due to how immer-reducers action generation works, adding default
parameters to the methods will NOT pass it to the action payload, which can
make your reducer impure and the values will not be available in middlewares.

```ts
class MyImmerReducer extends ImmerReducer<State> {
addItem (id: string = uuid()) {
this.draftState.ids.push([id])
}
}

immerActions.addItem() // generates empty payload { payload: [] }
```

As a workaround, create custom action creator wrappers that pass the default parameters instead.

```ts
class MyImmerReducer extends ImmerReducer<State> {
addItem (id) {
this.draftState.ids.push([id])
}
}

const actions = {
addItem: () => immerActions.addItem(id)
}
```


## 📚 Examples

Here's a more complete example with redux-saga and [redux-render-prop](https://github.com/epeli/redux-render-prop):
Expand Down

0 comments on commit e5ebca9

Please sign in to comment.