Skip to content

Profiler

In one line

<Profiler> measures render cost of its subtree — use the DevTools Profiler or the Profiler API for optimization.

In simple words

The Profiler has two forms:

  1. React DevTools Profiler — a visual tool that records all renders, shows flamecharts, commit times, and what caused each render. No code changes needed — just click Record.
  1. Profiler API — <Profiler id="..." onRender={callback}> wraps components and calls onRender with timing info after each render. Useful for programmatic performance monitoring.

The onRender callback receives: id, phase ("mount" or "update"), actualDuration, baseDuration, startTime, commitTime. Use it to log slow renders or send metrics to analytics.

Profiler adds overhead — only use in development or behind a feature flag in production.

Example

jsx
import { Profiler } from "react";

function onRender(id, phase, actualDuration, baseDuration) {
  console.log(`${id} ${phase}: ${actualDuration}ms`);
  if (actualDuration > 16) {
    console.warn(`Slow render: ${id} took ${actualDuration}ms`);
  }
}

function App() {
  return (
    <Profiler id="App" onRender={onRender}>
      <Header />
      <Profiler id="MainContent" onRender={onRender}>
        <MainContent />
      </Profiler>
      <Footer />
    </Profiler>
  );
}

Profiler calls onRender after each commit with timing data. Use it to identify and log slow renders programmatically.

Common confusions

  • Confused with: React DevTools Profiler

    The difference: The Profiler API (<Profiler> component) is programmatic — you write code to handle render timing data. The DevTools Profiler is visual — you click Record in the browser extension and see a flamechart. Use DevTools for investigation, Profiler API for continuous monitoring.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary