Eslint-plugin-react: react/display-name false positive when using React.memo

Created on 2 Jan 2019  路  3Comments  路  Source: yannickcr/eslint-plugin-react

[email protected]

We have a functional component that is exported with React.memo

import React from 'react'
import { string } from 'prop-types'

function Component({ world }) {
  return <div>Hello {world}</div>
}

Component.propTypes = {
  world: string,
}

export default React.memo(Component)

This triggers the react/display-name error after the update from 7.11.1

[...]/Component.jsx
  12:16  error  Component definition is missing display name  react/display-name

The exported components displayName is Memo(Component).

Without React.memo it recognizes the displayName.

export default Component
bug help wanted

Most helpful comment

The fix in 7.12.3 works for export default React.memo(Component);, but still gives a false positive if you wrap the function directly:

import React from 'react';

const Test = React.memo(props => (
  <div>{props.children}</div>
));
export default Test;

All 3 comments

cc @jomasti

The fix in 7.12.3 works for export default React.memo(Component);, but still gives a false positive if you wrap the function directly:

import React from 'react';

const Test = React.memo(props => (
  <div>{props.children}</div>
));
export default Test;

@samsch thanks, could you file that as a new issue?

Was this page helpful?
0 / 5 - 0 ratings