ESLint react/display-name warning on a React component
Component definition is missing display name react/display-nameShort answer
The react/display-name rule fires when React cannot work out a name for a component, so debugging messages have no name to show. Give the function a name: use function Name() inside memo, or export a named function. Setting displayName by hand also works.
Fix it fast
1Find out which cause you have
Run ESLint on the file the warning points to, so you see the exact line and which pattern triggers the rule.
npx eslint path/to/file.jsx --rule 'react/display-name: error'2Match what you see, then jump to its fix
- 1
The warning points at export default ({ a }) => { ... }An anonymous arrow function is the default exportFix - 2
The warning points at const Row = React.memo(({ a }) => { ... })An unnamed arrow function is passed to React.memoFix - 3
The warning points at a function that returns another component, or at createContext() with checkContextObjects turned onA component is created without a name you can see (wrapper, HOC or context)Fix
- 1
What does the error look like?
Component definition is missing display name react/display-name
Cause 1 of 3
An anonymous arrow function is the default export
1Check
Look for export default followed directly by an arrow function. It has no binding name, so the rule cannot see one.
grep -rn "export default (" app pages components2Fix
Declare the component with a name and export that name.
export default function Card({ title }) {
return <h2>{title}</h2>
}3Verify
Run ESLint again on the file.
npx eslint path/to/file.jsxConfirmed by github.com
Cause 2 of 3
An unnamed arrow function is passed to React.memo
1Check
A bare arrow inside memo is the pattern the rule documentation lists as incorrect.
grep -rn "memo((" app pages components2Fix
Pass a named function expression to memo. Its name becomes the display name.
const Row = React.memo(function Row({ a }) {
return <>{a}</>
})3Verify
Run ESLint again; the warning on that line should be gone.
npx eslint path/to/file.jsxConfirmed by github.com
Cause 3 of 3
A component is created without a name you can see (wrapper, HOC or context)
1Check
Read the rule options in your ESLint config. With ignoreTranspilerName: true the rule ignores the name inferred from the variable and asks for an explicit displayName. With checkContextObjects: true it also covers contexts.
grep -rn "display-name" eslint.config.* .eslintrc* 2>/dev/null2Fix
Set displayName yourself on the component or the context.
const ThemeContext = createContext(null)
ThemeContext.displayName = 'ThemeContext'
export default function Hello({ name }) {
return <div>Hello {name}</div>
}
Hello.displayName = 'Hello'3Verify
Run ESLint on the whole source folder.
npx eslint .Confirmed by github.com
How do I stop it coming back?
- Prefer function declarations (export default function Name) for components.
- Give every function passed to memo a name.
- Run ESLint in CI so unnamed components are caught on the pull request.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
ESLint says an element in a list is missing its key prop
react/jsx-key
react/jsx-key fires when an element returned from map, Array.from or an array literal has no key.
3 causes, each with a fixWeb apps
There is no tailwind.config.js after installing Tailwind 4 and HeroUI in Next.js
HeroUI components render unstyled
Nothing is broken: Tailwind CSS 4 is configured in CSS and no longer creates tailwind.config.js.
3 causes, each with a fixWeb apps
react-i18next shows the wrong plural form for a count, or prints the key instead of the text
t('item') prints the key item instead of a translated sentence
i18next picks a plural from the count option and looks for keys ending in _one, _other and so on.
4 causes, each with a fixWeb apps
useSession throws because there is no SessionProvider above it
[next-auth]: `useSession` must be wrapped in a <SessionProvider />
useSession reads the session from React Context, and SessionProvider is what creates that context.
3 causes, each with a fixWeb apps
next/link throws React.Children.only on its children
Error: React.Children.only expected to receive a single React element child.
React.Children.only accepts exactly one React element and throws for anything else, including an array with one item.
3 causes, each with a fixWeb apps
Hydration failed after adding next-themes dark mode
Console reports a server and client mismatch on the html element
next-themes changes the html element and knows the theme only in the browser, so server HTML and client HTML differ.
3 causes, each with a fix