Skip to content

Commit b4d6ac3

Browse files
wgao19timdorr
authored andcommitted
Add docs for batch() (#1271)
* Add `batch()` to docs * Make website work for `batch()` docs as well as on versioned docs
1 parent 5867fdc commit b4d6ac3

File tree

4 files changed

+92
-3
lines changed

4 files changed

+92
-3
lines changed

docs/api/batch.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
id: batch
3+
title: batch
4+
sidebar_label: batch()
5+
hide_title: true
6+
---
7+
8+
# `batch()`
9+
10+
```js
11+
batch(fn: Function)
12+
```
13+
14+
React's `unstable_batchedUpdate()` 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.
15+
16+
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:
17+
18+
```js
19+
import { batch } from "react-redux";
20+
21+
function myThunk() {
22+
return (dispatch, getState) => {
23+
// should only result in one combined re-render, not two
24+
batch(() => {
25+
dispatch(increment());
26+
dispatch(increment());
27+
})
28+
}
29+
}
30+
```
31+
32+
## References
33+
34+
- [`unstable_batchedUpdate()` API from React](https://github.com/facebook/react/commit/b41883fc708cd24d77dcaa767cde814b50b457fe)

website/sidebars.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
"api/connect",
1515
"api/provider",
1616
"api/connect-advanced",
17+
"api/batch",
1718
"api/hooks"
1819
],
19-
"Guides": [
20-
"troubleshooting"
21-
]
20+
"Guides": ["troubleshooting"]
2221
}
2322
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
id: version-7.x-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_batchedUpdate()` 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_batchedUpdate()` API from React](https://github.com/facebook/react/commit/b41883fc708cd24d77dcaa767cde814b50b457fe)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version-7.x-docs": {
3+
"Introduction": [
4+
"version-7.x-introduction/quick-start",
5+
"version-7.x-introduction/basic-tutorial",
6+
"version-7.x-introduction/why-use-react-redux"
7+
],
8+
"Using React Redux": [
9+
"version-7.x-using-react-redux/connect-mapstate",
10+
"version-7.x-using-react-redux/connect-mapdispatch",
11+
"version-7.x-using-react-redux/accessing-store"
12+
],
13+
"API Reference": [
14+
"version-7.x-api/connect",
15+
"version-7.x-api/provider",
16+
"version-7.x-api/connect-advanced",
17+
"version-7.x-api/batch"
18+
],
19+
"Guides": ["version-7.x-troubleshooting"]
20+
}
21+
}

0 commit comments

Comments
 (0)