Replies: 3 comments 3 replies
-
I think the framework handles batches itself. |
Beta Was this translation helpful? Give feedback.
-
Seems react native doesn't have support for it yet, I still see Its pretty simple to test if batching is working: import React, { useEffect, useState } from 'react';
import { Text, View, unstable_batchedUpdates } from 'react-native';
export const Test = () => {
const [counterOne, setCounterOne] = useState(0);
const [counterTwo, setCounterTwo] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
console.log('---------------');
// To batch just:
// unstable_batchedUpdates(() => {
setCounterOne((x) => x + 1);
setCounterTwo((x) => x + 1);
// });
}, 1000);
return () => {
clearInterval(interval);
};
}, []);
useEffect(() => {
console.log('Counter: ', counterOne, counterTwo);
}, [counterOne, counterTwo]);
return (
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}>
<Text>Counter One: {counterOne}</Text>
<Text>Counter Two: {counterTwo}</Text>
</View>
);
}; Also, I'm not sure if having hermes affects that.. but we're with hermes disabled |
Beta Was this translation helpful? Give feedback.
-
New Arch supports it |
Beta Was this translation helpful? Give feedback.
-
reference: reactwg/react-18#21
What is batching?
Batching is when React groups multiple state updates into a single re-render for better performance.
how can we achieve batch updates in React Native?
Beta Was this translation helpful? Give feedback.
All reactions