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

displayName in components should be static #2581

Closed
rondonjon opened this issue Feb 26, 2020 · 3 comments
Closed

displayName in components should be static #2581

rondonjon opened this issue Feb 26, 2020 · 3 comments
Labels

Comments

@rondonjon
Copy link

rondonjon commented Feb 26, 2020

The react/display-name documentation doesn't explicitly state it, but the rule seems to accept display names as properties inside components.

=> Documentation needs to be updated

When the displayName was defined as a property, I think the rule should ensure that the declaration is static, so the following case should be rejected:

class Demo extends Component {
  displayName = "Demo"
}

Whereas the following should be accepted:

class Demo extends Component {
  static displayName = "Demo"
}
@ljharb
Copy link
Member

ljharb commented Feb 26, 2020

We should definitely add test cases to ensure that a non-static class field does not satisfy the rule; additionally, we should probably add an option that forces it to be a static class field rather than an external property.

@ljharb
Copy link
Member

ljharb commented Feb 26, 2020

In your example, however, the function’s name is sufficient, and your non-static class field has no effect. You’d need to use an anonymous class with a non-static property to see if the rule really accepted it (i believe it won’t)

@ljharb
Copy link
Member

ljharb commented Feb 19, 2022

Either static-property-placement or no-typos should probably handle this.

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

No branches or pull requests

2 participants