README
react-batched-updates
Cross platform unstable_batchedUpdates
Usage
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.
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
.
import { setBatchedUpdates } from 'react-batched-updates'
import { act } from '@testing-library/react'
setBatchedUpdates(act)