Skip to content

react/display-name false positive when using React.memo #2105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Raigen opened this issue Jan 2, 2019 · 3 comments
Closed

react/display-name false positive when using React.memo #2105

Raigen opened this issue Jan 2, 2019 · 3 comments

Comments

@Raigen
Copy link

Raigen commented Jan 2, 2019

[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
@ljharb
Copy link
Member

ljharb commented Jan 2, 2019

cc @jomasti

ljharb added a commit that referenced this issue Jan 3, 2019
[Fix] `display-name`: fix false positive for `React.memo`

Fixes #2105.
@samsch
Copy link
Contributor

samsch commented Jan 13, 2019

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;

@ljharb
Copy link
Member

ljharb commented Jan 13, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants