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
document alternative callback-builder-style notation for actions… (#268)
* alternative callback-builder-style notation for actionsMap
* Clarify builder usage purpose
* Fix formatting and wording
* Fix TS usage in createSlice example
Instead of using a simple object as an argument to `createReducer`, you can also provide a callback that receives an `ActionReducerMapBuilder` instance:
55
+
56
+
```typescript
57
+
createReducer(0, builder=>
58
+
builder.add(increment, (state, action) => {
59
+
// action is inferred correctly here
60
+
})
61
+
)
62
+
```
63
+
64
+
This is intended for use with TypeScript, as passing a plain object full of reducer functions cannot infer their types correctly in this case. It has no real benefit when used with plain JS.
65
+
66
+
We recommend using this API if stricter type safety is necessary when defining reducer argument objects.
67
+
52
68
## Direct State Mutation
53
69
54
70
Redux requires reducer functions to be pure and treat state values as immutable. While this is essential for making state updates predictable and observable, it can sometimes make the implementation of such updates awkward. Consider the following example:
0 commit comments