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
As of RTK 2.0, the `autoBatchEnhancer` is included by default when calling `configureStore`.
74
+
75
+
This means to configure it, you should instead pass an callback that receives `getDefaultEnhancers` and calls it with your desired settings.
76
+
77
+
```tstitle="Configuring autoBatchEnhancer with getDefaultEnhancers"
78
+
import { configureStore } from'@reduxjs/toolkit'
79
+
80
+
const store =configureStore({
81
+
reducer: () =>0,
82
+
enhancers: (getDefaultEnhancers) =>
83
+
getDefaultEnhancers({
84
+
autoBatch: { type: 'tick' },
85
+
}),
86
+
})
87
+
```
88
+
89
+
:::
90
+
77
91
Creates a new instance of the autobatch store enhancer.
78
92
79
93
Any action that is tagged with `action.meta[SHOULD_AUTOBATCH] = true` will be treated as "low-priority", and a notification callback will be queued. The enhancer will delay notifying subscribers until either:
@@ -140,4 +154,4 @@ This allows Redux users to selectively tag certain actions for effective batchin
RTK Query already marks several of its key internal action types as batchable. By adding the `autoBatchEnhancer` to the store setup, it improves the overall UI performance, especially when rendering large lists of components that use the RTKQ query hooks.
Copy file name to clipboardExpand all lines: docs/api/configureStore.mdx
+47-6Lines changed: 47 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -77,7 +77,7 @@ If it is an object of slice reducers, like `{users : usersReducer, posts : posts
77
77
78
78
### `middleware`
79
79
80
-
An optional array of Redux middleware functions
80
+
An optional array of Redux middleware functions, or a callback to customise the array of middleware.
81
81
82
82
If this option is provided, it should contain all the middleware functions you
83
83
want added to the store. `configureStore` will automatically pass those to `applyMiddleware`.
@@ -118,17 +118,58 @@ An optional array of Redux store enhancers, or a callback function to customize
118
118
119
119
If defined as an array, these will be passed to [the Redux `compose` function](https://redux.js.org/api/compose), and the combined enhancer will be passed to `createStore`.
120
120
121
-
This should _not_ include `applyMiddleware()` or the Redux DevTools Extension `composeWithDevTools`, as those are already handled by `configureStore`.
121
+
:::tip Dev Tools
122
+
This should _not_ include the Redux DevTools Extension `composeWithDevTools`, as this is already handled by `configureStore`.
122
123
123
-
Example: `enhancers: [offline]` will result in a final setup of `[applyMiddleware, offline, devToolsExtension]`.
124
+
Example: `enhancers: [offline]` will result in a final setup of `[offline, devToolsExtension]`.
125
+
:::
124
126
125
-
If defined as a callback function, it will be called with the existing array of enhancers _without_ the DevTools Extension (currently `[applyMiddleware]`),
126
-
and should return a new array of enhancers. This is primarily useful for cases where a store enhancer needs to be added
127
-
in front of `applyMiddleware`, such as `redux-first-router` or `redux-offline`.
127
+
If not provided, `configureStore` will call `getDefaultEnhancers` and use the array of enhancers it returns (including `applyMiddleware` with specified middleware).
128
+
129
+
Where you wish to add onto or customize the default enhancers, you may pass a callback function that will receive `getDefaultEnhancers` as its argument, and should return an enhancer array.
128
130
129
131
Example: `enhancers: (defaultEnhancers) =>defaultEnhancers.prepend(offline)` will result in a final setup
130
132
of `[offline, applyMiddleware, devToolsExtension]`.
131
133
134
+
For more details on how the `enhancer` parameter works and the list of enhancers that are added by default, see the [`getDefaultEnhancers` docs page](./getDefaultEnhancers).
135
+
136
+
:::caution Middleware
137
+
138
+
In order to use any [middleware](#middleware) specified, you _need_ to use the `getDefaultEnhancers` callback, which will include the built `applyMiddleware` enhancer.
139
+
140
+
If you provide an array, this `applyMiddleware` enhancer will _not_ be used.
141
+
142
+
`configureStore` will warn in console if any middleware are provided (or left as default) but not included in the final list of enhancers.
143
+
144
+
```tsno-transpile
145
+
// warns - middleware left as default but not included in final enhancers
146
+
configureStore({
147
+
reducer,
148
+
enhancers: [offline],
149
+
})
150
+
// warns - middleware customised but not included in final enhancers
0 commit comments