Q28: How do you profile and debug unnecessary re-renders using React DevTools Profiler?
The React DevTools Profiler records component render metrics. It classifies renders using Flamecharts and Ranked charts, highlighting why each component rendered (e.g., 'Props changed', 'State changed', or 'Parent component rendered').
Programmatic Profiler API Usage
import { Profiler } from 'react';
function onRenderCallback(id, phase, actualDuration) {
console.log(`[${id}] ${phase} phase took ${actualDuration}ms`);
}
<Profiler id="Navigation" onRender={onRenderCallback}>
<NavigationComponent />
</Profiler>The Profiler component records exact render execution duration and phase lifecycle details.
Key Takeaways
Profiler pinpoints render durations and root causes.
Look for 'Parent component rendered' to identify components missing
React.memo.
Knowledge Check
In React DevTools Profiler, what does 'Parent component rendered' mean under render reason?