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
This guide is brought to you by DodaTech — built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.
← Previous
How to Fix React Component defaultProps Not Working
Next →
How to Fix React Error Boundary Not Catching Errors
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro