Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

ESLint react/display-name warning on a React component

ErrorComponent definition is missing display name react/display-name

Short 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.

  • Applies to eslint-plugin-react 7, ESLint 9, React 19, Next.js 15
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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'
  2. 2Match what you see, then jump to its fix

    1. 1The warning points at export default ({ a }) => { ... }An anonymous arrow function is the default exportFix
    2. 2The warning points at const Row = React.memo(({ a }) => { ... })An unnamed arrow function is passed to React.memoFix
    3. 3The 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

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 components

2Fix

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.jsx

Confirmed by github.com

Did this fix it?

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 components

2Fix

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.jsx

Confirmed by github.com

Did this fix it?

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/null

2Fix

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

Did this fix it?

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:

Related fixes

Web 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 fix

Web 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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.