Capítulo 68 de 116
<Profiler> measures the actual rendering cost of a subtree programmatically — wrap any part of the tree in it, supply an onRender callback, and get timing data on every commit for that subtree, useful for automated performance regression tracking outside the DevTools Profiler UI.
id (a string identifying this Profiler in the callback data) and onRender (a callback function React calls after every commit within the wrapped subtree).onRender receives detailed timing data: which Profiler id, the phase ("mount" for the first render, "update" for subsequent ones), actualDuration (time spent rendering this commit), baseDuration (an estimate of how long the subtree would take without any memoization), plus commit start/end timestamps.<Profiler> components can be nested to measure different granularities within the same tree — each fires its own onRender independently.<Profiler> component is for programmatic, automated measurement (e.g. feeding into performance monitoring/CI).<Profiler id="Sidebar" onRender={(id, phase, actualDuration) => {
logPerf({ id, phase, actualDuration });
}}>
<Sidebar />
</Profiler>
<Profiler> for programmatic/automated performance measurement; use the DevTools Profiler panel (Ch 10) for interactive investigation.actualDuration vs. baseDuration is the key comparison for judging whether existing memoization is actually paying off.onRender callback fires in response to.