Skip to content

Commit 979f933

Browse files
authored
Merge pull request #3409 from reduxjs/v2.0-docs
Begin updating docs for 2.0 changes
2 parents 430a8e4 + 639ec4d commit 979f933

22 files changed

+832
-218
lines changed

docs/api/autoBatchEnhancer.mdx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,9 @@ const counterSlice = createSlice({
4848
})
4949
const { incrementBatched, decrementUnbatched } = counterSlice.actions
5050

51+
// includes batch enhancer by default, as of RTK 2.0
5152
const store = configureStore({
5253
reducer: counterSlice.reducer,
53-
// highlight-start
54-
enhancers: (getDefaultEnhancers) => {
55-
// Add the autobatch enhancer to the store setup
56-
return getDefaultEnhancers().concat(autoBatchEnhancer())
57-
},
58-
// highlight-end
5954
})
6055
```
6156

@@ -74,6 +69,25 @@ type AutoBatchOptions =
7469
export type autoBatchEnhancer = (options?: AutoBatchOptions) => StoreEnhancer
7570
```
7671
72+
:::tip
73+
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+
```ts title="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+
7791
Creates a new instance of the autobatch store enhancer.
7892

7993
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
140154
141155
### RTK Query and Batching
142156
143-
RTK Query already marks several of its key internal action types as batchable. If you add the `autoBatchEnhancer` to the store setup, it will improve the overall UI performance, especially when rendering large lists of components that use the RTKQ query hooks.
157+
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.

0 commit comments

Comments
 (0)