0
0
Reactframework~8 mins

Functional components in React - Performance & Optimization

Choose your learning style9 modes available
Performance: Functional components
MEDIUM IMPACT
This affects initial page load speed and interaction responsiveness by how React renders and updates UI components.
Creating a simple UI component in React
React
function Button({ label }) {
  return <button>{label}</button>;
}
Functional components are simpler, use less memory, and React can optimize rendering better.
📈 Performance GainReduces memory usage and speeds up rendering by avoiding class instance overhead
Creating a simple UI component in React
React
class Button extends React.Component {
  render() {
    return <button>{this.props.label}</button>;
  }
}
Class components have more boilerplate and React must create an instance, which adds overhead.
📉 Performance CostAdds extra memory for instances and slower updates due to lifecycle methods
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Class component with instanceMore nodes due to lifecycle wrappersMultiple reflows if state changes trigger full re-rendersHigher paint cost due to extra DOM updates[X] Bad
Functional component with hooksMinimal nodes, direct function callsSingle reflow per state changeLower paint cost due to optimized updates[OK] Good
Rendering Pipeline
Functional components are called as functions during React's render phase. React compares the returned elements to the previous render to update the DOM efficiently.
JavaScript Execution
Virtual DOM Diffing
DOM Updates
Paint
⚠️ BottleneckJavaScript Execution and Virtual DOM Diffing when many components re-render unnecessarily
Core Web Vital Affected
INP
This affects initial page load speed and interaction responsiveness by how React renders and updates UI components.
Optimization Tips
1Use functional components to reduce memory and lifecycle overhead.
2Memoize callbacks and values to avoid unnecessary re-renders.
3Keep components small and focused to minimize JavaScript work.
Performance Quiz - 3 Questions
Test your performance knowledge
Why do functional components generally improve interaction responsiveness compared to class components?
AThey avoid creating class instances and lifecycle overhead
BThey use more memory which speeds up rendering
CThey block the main thread longer to batch updates
DThey force full page reloads on state changes
DevTools: React DevTools and Performance panel
How to check: Open React DevTools Profiler, record interactions, and observe component render counts and durations. Use Performance panel to see JS execution and paint times.
What to look for: Look for fewer component re-renders and shorter JS execution times indicating efficient functional component usage