Skip to content

Commit ca9afdb

Browse files
committed
Version 7.2 docs
1 parent 043517e commit ca9afdb

File tree

11 files changed

+2653
-0
lines changed

11 files changed

+2653
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
id: version-7.2-batch
3+
title: batch
4+
sidebar_label: batch()
5+
hide_title: true
6+
original_id: batch
7+
---
8+
9+
# `batch()`
10+
11+
```js
12+
batch(fn: Function)
13+
```
14+
15+
React's `unstable_batchedUpdates()` API allows any React updates in an event loop tick to be batched together into a single render pass. React already uses this internally for its own event handler callbacks. This API is actually part of the renderer packages like ReactDOM and React Native, not the React core itself.
16+
17+
Since React-Redux needs to work in both ReactDOM and React Native environments, we've taken care of importing this API from the correct renderer at build time for our own use. We also now re-export this function publicly ourselves, renamed to `batch()`. You can use it to ensure that multiple actions dispatched outside of React only result in a single render update, like this:
18+
19+
```js
20+
import { batch } from 'react-redux'
21+
22+
function myThunk() {
23+
return (dispatch, getState) => {
24+
// should only result in one combined re-render, not two
25+
batch(() => {
26+
dispatch(increment())
27+
dispatch(increment())
28+
})
29+
}
30+
}
31+
```
32+
33+
## References
34+
35+
- [`unstable_batchedUpdates()` API from React](https://github.com/facebook/react/commit/b41883fc708cd24d77dcaa767cde814b50b457fe)

0 commit comments

Comments
 (0)