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
To handle these actions in your reducers, reference the action creators in `createReducer` or `createSlice` using either the object key notation or the "builder callback" notation. (Note that if you use TypeScript, you [should use the "builder callback" notation to ensure the types are inferred correctly](../usage/usage-with-typescript.md#type-safety-with-extrareducers)):
213
+
To handle these actions in your reducers, reference the action creators in `createReducer` or `createSlice` using the "builder callback" notation.
Copy file name to clipboardExpand all lines: docs/api/createReducer.mdx
+1-16Lines changed: 1 addition & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -37,9 +37,7 @@ function counterReducer(state = initialState, action) {
37
37
This approach works well, but is a bit boilerplate-y and error-prone. For instance, it is easy to forget the `default` case or
38
38
setting the initial state.
39
39
40
-
The `createReducer` helper streamlines the implementation of such reducers. It supports two different forms of defining case
41
-
reducers to handle actions: a "builder callback" notation and a "map object" notation. Both are equivalent, but the "builder callback"
42
-
notation is preferred.
40
+
The `createReducer` helper streamlines the implementation of such reducers. It uses a "builder callback" notation to define handlers for specific action types, matching against a range of actions, or handling a default case. This is conceptually similar to a switch statement, but with better TS support.
43
41
44
42
With `createReducer`, your reducers instead look like:
Similarto`createReducer`, the`extraReducers`fieldusesa"builder callback"notationtodefinehandlersforspecificactiontypes, matchingagainstarangeofactions, orhandlingadefaultcase. Thisisconceptuallysimilartoaswitchstatement, butwithbetterTSsupportasitcaninfertheactiontypefromtheprovidedactioncreator. It's particularly useful for working with actions produced by `createAction` and `createAsyncThunk`.
0 commit comments