Skip to content

How to Fix React Component displayName Missing

DodaTech Updated 2026-06-26 1 min read

The Problem

In this quick-fix, you'll learn how to set displayName for meaningful DevTools output. This matters because anonymous component names make profiling nearly impossible. In real-world applications, this pattern appears in large component trees with dozens of anonymous HOC wrappers.

The Wrong Way

const Button = React.forwardRef((props, ref) => <button ref={ref} />);
const withLogger = (C) => (props) => <C {...props} />;
const LoggedBtn = withLogger(Button);
In DevTools: <ForwardRef> <Unknown>

The Right Way

Button.displayName = 'Button';
const withLogger = (C) => {
  const Logged = (props) => <C {...props} />;
  Logged.displayName = 'withLogger(' + (C.displayName || C.name) + ')';
  return Logged;
};
In DevTools: <Button> <withLogger(Button)>

Prevention

  • Set displayName on forwardRef and memo
  • Name HOCs with wrapped component name
  • Name function components - avoid anonymous exports

FAQ

### Why does displayName matter for profiling??

DevTools uses displayName to label components in profiler. Without names, finding unnecessary re-renders becomes guesswork in large apps.

Does displayName affect production??

It adds bytes but has no behavioral effect. Some teams strip displayName in production builds.

How to set displayName for lazy components??

const Lazy = React.lazy(() => import('./Comp')); Lazy.displayName = 'LazyComp';

This guide is brought to you by DodaTech — built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro