Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions docs/api/autoBatchEnhancer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,9 @@ const counterSlice = createSlice({
})
const { incrementBatched, decrementUnbatched } = counterSlice.actions

// includes batch enhancer by default, as of RTK 2.0
const store = configureStore({
reducer: counterSlice.reducer,
// highlight-start
enhancers: (getDefaultEnhancers) => {
// Add the autobatch enhancer to the store setup
return getDefaultEnhancers().concat(autoBatchEnhancer())
},
// highlight-end
})
```

Expand All @@ -74,6 +69,25 @@ type AutoBatchOptions =
export type autoBatchEnhancer = (options?: AutoBatchOptions) => StoreEnhancer
```

:::tip
As of RTK 2.0, the `autoBatchEnhancer` is included by default when calling `configureStore`.

This means to configure it, you should instead pass an callback that receives `getDefaultEnhancers` and calls it with your desired settings.

```ts title="Configuring autoBatchEnhancer with getDefaultEnhancers"
import { configureStore } from '@reduxjs/toolkit'

const store = configureStore({
reducer: () => 0,
enhancers: (getDefaultEnhancers) =>
getDefaultEnhancers({
autoBatch: { type: 'tick' },
}),
})
```

:::

Creates a new instance of the autobatch store enhancer.

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:
Expand Down Expand Up @@ -140,4 +154,4 @@ This allows Redux users to selectively tag certain actions for effective batchin

### RTK Query and Batching

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.
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.
Loading