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/configureStore.mdx
+27-6Lines changed: 27 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,16 +9,36 @@ hide_title: true
9
9
10
10
# `configureStore`
11
11
12
-
A friendly abstraction over the standard Redux `createStore` function that adds good defaults
13
-
to the store setup for a better development experience.
12
+
The standard method for creating a Redux store. It uses the low-level Redux core `createStore` method internally, but wraps that to provide good defaults to the store setup for a better development experience.
13
+
14
+
## Purpose and Behavior
15
+
16
+
A standard Redux store setup typically requires multiple pieces of configuration:
17
+
18
+
- Combining the slice reducers into the root reducer
19
+
- Creating the middleware enhancer, usually with the thunk middleware or other side effects middleware, as well as middleware that might be used for development checks
20
+
- Adding the Redux DevTools enhancer, and composing the enhancers together
21
+
- Calling `createStore`
22
+
23
+
Legacy Redux usage patterns typically required several dozen lines of copy-pasted boilerplate to achieve this.
24
+
25
+
Redux Toolkit's `configureStore` simplifies that setup process, by doing all that work for you. One call to `configureStore` will:
26
+
27
+
- Call `combineReducers` to combine your slices reducers into the root reducer function
28
+
- Add the thunk middleware and called `applyMiddleware`
29
+
- In development, automatically add more middleware to check for common mistakes like accidentally mutating the state
30
+
- Automatically set up the Redux DevTools Extension connection
31
+
- Call `createStore` to create a Redux store using that root reducer and those configuration options
32
+
33
+
`configureStore` also offers an improved API and usage patterns compared to the original `createStore` by accepting named fields for `reducer`, `preloadedState`, `middleware`, `enhancers`, and `devtools`, as well as much better TS type inference.
14
34
15
35
## Parameters
16
36
17
37
`configureStore` accepts a single configuration object parameter, with the following options:
18
38
19
39
```ts no-transpile
20
40
typeConfigureEnhancersCallback= (
21
-
defaultEnhancers:StoreEnhancer[]
41
+
defaultEnhancers:EnhancerArray<[StoreEnhancer]>
22
42
) =>StoreEnhancer[]
23
43
24
44
interfaceConfigureStoreOptions<
@@ -107,7 +127,8 @@ a list of the specific options that are available.
107
127
Defaultsto`true`.
108
128
109
129
#### `trace`
110
-
TheReduxDevToolsExtensionrecentlyadded [supportforshowingactionstacktraces](https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/Features/Trace.md) that show exactly where each action was dispatched.
130
+
131
+
TheReduxDevToolsExtensionrecentlyadded [supportforshowingactionstacktraces](https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/Features/Trace.md) that show exactly where each action was dispatched.
Copy file name to clipboardExpand all lines: docs/api/createListenerMiddleware.mdx
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -422,6 +422,8 @@ These methods provide the ability to write conditional logic based on future dis
422
422
423
423
Both these methods are cancellation-aware, and will throw a `TaskAbortError` if the listener instance is cancelled while paused.
424
424
425
+
Note that both `take` and `condition` will only resolve **after the next action** has been dispatched. They do not resolve immediately even if their predicate would return true for the current state.
426
+
425
427
### Child Tasks
426
428
427
429
-`fork: (executor: (forkApi: ForkApi) => T | Promise<T>) => ForkedTask<T>`: Launches a "child task" that may be used to accomplish additional work. Accepts any sync or async function as its argument, and returns a `{result, cancel}` object that can be used to check the final status and return value of the child task, or cancel it while in-progress.
@@ -831,7 +833,7 @@ First, you can import effect callbacks from slice files into the middleware file
Conceptually, eachslicereducer"owns"itssliceofstate. There's also a natural correspondance between the update logic defined inside `reducers`, and the action types that are generated based on those.
However, unlikethe`reducers`field, eachindividualcasereducerinsideof`extraReducers`will_not_generateanewactiontypeoractioncreator.
148
+
149
+
Iftwofieldsfrom`reducers`and`extraReducers`happentoendupwiththesameactiontypestring, the function from `reducers` will be used to handle that action type.
149
150
150
151
### The`extraReducers`"builder callback"notation
151
152
@@ -162,6 +163,14 @@ See [the "Builder Callback Notation" section of the `createReducer` reference](.
0 commit comments