Skip to content
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

react/display-name false positive in render prop ternary #2224

Closed
jaydenseric opened this issue Apr 3, 2019 · 6 comments
Closed

react/display-name false positive in render prop ternary #2224

jaydenseric opened this issue Apr 3, 2019 · 6 comments

Comments

@jaydenseric
Copy link

The react/display-name rule has a false positive error when a component render prop is a ternary containing an arrow function expression:

<Section renderFigure={image ? () => <img src={image.src} /> : null} />

This does not have an error:

<Section renderFigure={() => <img src={image.src} />} />

So the ternary must confuse the rule somehow.

Screen Shot 2019-04-03 at 4 02 16 pm

@ljharb
Copy link
Member

ljharb commented Apr 3, 2019

In this case, the arrow function is considered a component.

It seems worth improving our component detection to avoid render props - cc @alexzherdev

@pawelnvk
Copy link
Contributor

Just a side-note, but I would rather expect ternary inside of callback instead of passing callback if ternary is fulfilled.

@jzabala
Copy link
Contributor

jzabala commented Jul 10, 2020

This doesn't happen with versions:

"babel-eslint": "^10.1.0"
"eslint": "^7.4.0"
"eslint-plugin-react": "^7.20.3"

Screen Shot 2020-07-10 at 6 33 04 PM

@ljharb
Copy link
Member

ljharb commented Jul 10, 2020

@jzabala your screenshot shows that the false positive does happen?

@jzabala
Copy link
Contributor

jzabala commented Jul 10, 2020

@jzabala your screenshot shows that the false positive does happen?

Sorry for the confusing screenshot 😅 . I wanted to show that the rule was active, since it is triggered at the bottom, but it is not triggered in the case reported in the issue (the ternary). So, this issue is fixed in the specified versions.

@ljharb
Copy link
Member

ljharb commented Jul 10, 2020

ah, thanks. Closing, then :-)

@ljharb ljharb closed this as completed Jul 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants