Skip to content

Instantly share code, notes, and snippets.

@piaskowyk
Created March 19, 2025 16:59
Show Gist options
  • Save piaskowyk/30de1d0859a4d614a96333f8d81d7d75 to your computer and use it in GitHub Desktop.
Save piaskowyk/30de1d0859a4d614a96333f8d81d7d75 to your computer and use it in GitHub Desktop.
import { useEffect, useState, Profiler } from 'react';
import { Button, View } from 'react-native';
const AMOUNT = 1000;
function TestView() {
return (
<View style={[
{ width: 100, height: 1, backgroundColor: 'red', flex: 1 },
]} />
);
}
function List() {
const start = Date.now();
useEffect(() => {
const end = Date.now();
console.log('Time:', (end - start)/AMOUNT);
}, []);
return (
<>
{Array.from({ length: AMOUNT }).map((_, index) => (
<TestView key={index} />
))}
</>
);
}
export default function HomeScreen() {
const [toggle, setToggle] = useState(false);
return (
<Profiler id="HomeScreen" onRender={(...args) => console.log('Profiler:', args)}>
<View style={{ flex: 1, paddingTop: 100 }}>
<Button title="Press me" onPress={() => setToggle(!toggle)} />
{ toggle && <List /> }
</View>
</Profiler>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment