Performance optimization in React is about minimizing unnecessary work. React is fast by default, but complex apps may need optimization.
Measuring Performance
Use React DevTools Profiler and browser performance tools to identify bottlenecks before optimizing. Premature optimization is counterproductive.
Memoization
React.memo, useMemo, and useCallback prevent unnecessary recalculations and re-renders. Use them when you have expensive computations or stable callback references.
Code Splitting
Reduce initial bundle size with dynamic imports and React.lazy. Load components only when needed.
Virtualization
For long lists, render only visible items using libraries like react-window or TanStack Virtual.
Keys and Reconciliation
Proper key usage helps React efficiently update lists. Never use array indices as keys if the list can reorder.