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
Copy file name to clipboardExpand all lines: docs/api/createReducer.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ This approach works well, but is a bit boilerplate-y and error-prone. For instan
29
29
The `createReducer` helper streamlines the implementation of such reducers. It takes two arguments. The first one is the initial state. The second is an object mapping from action types to _case reducers_, each of which handles one specific action type.
30
30
31
31
```js
32
-
constcounterReducer=createReducr(0, {
32
+
constcounterReducer=createReducer(0, {
33
33
increment: (state, action) => state +action.payload,
34
34
decrement: (state, action) => state -action.payload
35
35
})
@@ -41,7 +41,7 @@ If you created action creators using `createAction()`, you can use those directl
41
41
constincrement=createAction('increment')
42
42
constdecrement=createAction('decrement')
43
43
44
-
constcounterReducer=createReducr(0, {
44
+
constcounterReducer=createReducer(0, {
45
45
[increment]: (state, action) => state +action.payload,
46
46
[decrement]: (state, action) => state -action.payload
47
47
})
@@ -55,7 +55,7 @@ Redux requires reducer functions to be pure and treat state values as immutable.
55
55
constaddTodo=createAction('todos/add')
56
56
consttoggleTodo=createAction('todos/toggle')
57
57
58
-
consttodosReducer=createReducr([], {
58
+
consttodosReducer=createReducer([], {
59
59
[addTodo]: (state, action) => {
60
60
consttodo=action.payload
61
61
return [...state, todo]
@@ -80,7 +80,7 @@ To make things easier, `createReducer` uses [immer](https://github.com/mweststra
80
80
constaddTodo=createAction('todos/add')
81
81
consttoggleTodo=createAction('todos/toggle')
82
82
83
-
consttodosReducer=createReducr([], {
83
+
consttodosReducer=createReducer([], {
84
84
[addTodo]: (state, action) => {
85
85
// This push() operation gets translated into the same
86
86
// extended-array creation as in the previous example.
If you choose to write reducers in this style, make sure to learn about the [pitfalls mentioned in the immer docs](https://github.com/mweststrate/immer#pitfalls) . Most importantly, you need to ensure that you either mutate the `state` argument or return a new state, _but not both_. For example, the following reducer would throw an exception if a `toggleTodo` action is passed:
0 commit comments