Performance optimization in React Native focuses on reducing unnecessary re-renders, improving UI responsiveness, optimizing memory usage, and ensuring smooth animations. A well-optimized app delivers better user experience, lower battery consumption, and faster load times.
React Native uses a JavaScript thread and a native UI thread. Performance issues usually occur when heavy logic blocks the JS thread or when frequent re-renders overload the reconciliation process.
Key tools include React.memo, useCallback, useMemo, FlatList, and InteractionManager.
// Using React.memo to prevent unnecessary re-renders
import React from "react";
import { Text } from "react-native";
const OptimizedText = React.memo(({ value }) => {
return {value} ;
});
export default OptimizedText;
// Optimized FlatList for rendering large lists
import { FlatList, Text } from "react-native";
const data = Array.from({ length: 1000 }, (_, i) => i);
export default function App() {
return (
item.toString()}
renderItem={({ item }) => {item} }
initialNumToRender={10}
/>
);
}
The React.memo example prevents re-rendering unless props change, while FlatList renders only visible items instead of the entire list at once.
Click the button below to update the Parent State. Notice how the two components react.
Parent Count: 0
Re-renders every time parent updates, even if props didn't change.
Only re-renders if its own props change (saved resources).
This visualization mimics React.memo. In a real app, the "Normal" component would waste CPU cycles redrawing the same content, causing lag.
FlatList instead of ScrollView for long listsuseCallbackScrollViewFlatListReact.memo and compare results