An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# react-batched-updates

[![npm](https://img.shields.io/npm/v/react-batched-updates.svg)](https://www.npmjs.com/package/react-batched-updates)
[![Code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](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)
```