https://github.com/alloc/react-batched-updates
Cross platform unstable_batchedUpdates for React libraries
https://github.com/alloc/react-batched-updates
Last synced: 10 months ago
JSON representation
Cross platform unstable_batchedUpdates for React libraries
- Host: GitHub
- URL: https://github.com/alloc/react-batched-updates
- Owner: alloc
- License: mit
- Created: 2021-04-02T13:28:28.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-08-10T19:49:07.000Z (over 4 years ago)
- Last Synced: 2025-03-26T07:28:21.689Z (11 months ago)
- Language: TypeScript
- Homepage:
- Size: 4.88 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - react-batched-updates
README
# react-batched-updates
[](https://www.npmjs.com/package/react-batched-updates)
[](https://github.com/prettier/prettier)
[](https://paypal.me/alecdotbiz)
> Cross platform unstable_batchedUpdates
## Usage
```ts
import { batchedUpdates } from 'react-batched-updates'
batchedUpdates(() => {
// Any setState calls are batched, instead of triggering
// multiple render passes.
})
```
You should call `setBatchedUpdates` or else `batchedUpdates` will be ineffective.
Except for React Native users, where the bundler prefers `cjs/index.native.js`,
a module that requires `react-native` to achieve zero configuration.
```ts
import { setBatchedUpdates } from 'react-batched-updates'
import { unstable_batchedUpdates } from 'react-dom'
// Both react-native and react-dom have this export.
setBatchedUpdates(unstable_batchedUpdates)
```
In test environments, you can usually replace `unstable_batchedUpdates` with `act`.
```ts
import { setBatchedUpdates } from 'react-batched-updates'
import { act } from '@testing-library/react'
setBatchedUpdates(act)
```