-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
3.6.2: 'react/display-name' throws false-positive in mixin methods that return JSX #256
Comments
Ditto. I wonder if it were enough to just apply this rule on functions that are declared at the top level and return JSX... |
Actually your mixin is a valid stateless function component, you can totally render it with (Even so, I've found a few issues with stateless functions and |
@yannickcr I don't think display-name should be used on plain function component or did I miss something? Can we just disable checking for display-name on component function? (ps: Thank's for the plugin 💯) |
This is a pretty frustrating bug actually. I'm getting multiple |
@iam4x That's an interesting question too. There's no mention of it in the 0.14 release notes, but it seems like displayName should be supported. It's a semi-defacto-standard not-React-specific thing after all. |
I believe the |
The displayName can be calculated implicitly by using the function name, or specified explicitly using displayName. The react dev tools will use displayName for function components if provided (http://codepen.io/epmatsw/pen/dYZxwB), which makes me think that that's an intentional feature of function components. You can write "anonymous" traditional components, but it's generally agreed as a bad practice, as evidenced by this rule. Since from a debugging perspective the two types of component are indistinguishable, I don't think it makes sense to treat them differently. Perhaps a reasonable compromise would be to add an opt-out flag to allow function components to not have a displayName? |
That code pen does not prove that it's an intentional feature. That's just where the property is looked for on the prototype/class. In the case of simple function components, it's the same place. Adding a I wasn't advocating writing anonymous components. I was just using it as an example. |
I just published Also, if you do not want to set a |
In the latest release, I'm hitting what appears to be a false-positive on display-name in a mixin. Here's a simplified example of the code that triggers it.
It wasn't triggered prior to 3.6.0 -- I suspect it may be related to the changes to support stateless function components here: #237
A temporary work-around is to assign the JSX to a variable, and then return that. It only seems to trigger when a block of JSX is directly returned from the method.
The text was updated successfully, but these errors were encountered: