0
0
Reactframework~8 mins

State vs props comparison in React - Performance Comparison

Choose your learning style9 modes available
Performance: State vs props comparison
MEDIUM IMPACT
This concept affects how React components update and re-render, impacting interaction responsiveness and rendering speed.
Passing data to child components and managing updates
React
function Parent() {
  const data = { value: 42 };
  return <Child data={data} />;
}

function Child({ data }) {
  // use props directly without copying to state
  return <div>{data.value}</div>;
}
Using props directly avoids extra state and re-renders, improving rendering speed and reducing memory use.
📈 Performance GainSingle render per update; avoids unnecessary re-renders and memory overhead.
Passing data to child components and managing updates
React
function Parent() {
  const [count, setCount] = React.useState(0);
  const data = { value: 42 };
  return <Child data={data} />;
}

function Child({ data }) {
  const [localData, setLocalData] = React.useState(data);
  // copies props to state unnecessarily
  return <div>{localData.value}</div>;
}
Copying props into state causes extra memory use and can lead to stale data or unnecessary re-renders.
📉 Performance CostTriggers extra re-renders and memory usage; can cause multiple renders per update.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Copy props to state unnecessarilyExtra virtual DOM nodes createdMultiple reflows per updateHigher paint cost due to repeated updates[X] Bad
Use props directly without copyingMinimal DOM operationsSingle reflow per updateLower paint cost[OK] Good
Frequent state updates without memoizationMany DOM updatesMany reflowsHigh paint cost[!] Bad
State updates with useCallback and memoOptimized DOM updatesReduced reflowsLower paint cost[OK] Good
Rendering Pipeline
Props and state changes trigger React's reconciliation process, leading to virtual DOM diffing, then real DOM updates causing layout and paint.
Reconciliation
Layout
Paint
⚠️ BottleneckReconciliation and Layout stages are most expensive when state changes cause many re-renders.
Core Web Vital Affected
INP
This concept affects how React components update and re-render, impacting interaction responsiveness and rendering speed.
Optimization Tips
1Avoid copying props into state unless you need to modify the data locally.
2Use props for static or read-only data to reduce re-renders.
3Memoize callbacks and components to prevent unnecessary updates.
Performance Quiz - 3 Questions
Test your performance knowledge
Why is copying props into state usually a bad idea for performance?
AIt causes extra re-renders and memory use
BIt reduces the number of renders
CIt makes components load faster
DIt improves browser caching
DevTools: React DevTools and Chrome Performance panel
How to check: Use React DevTools Profiler to record interactions and see component re-renders; use Chrome Performance to check layout and paint times.
What to look for: Look for unnecessary re-renders in React DevTools and long layout or paint durations in Performance panel indicating inefficient state/props usage.