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

JSX: "component definition is missing display name" #139

Closed
saschagehlich opened this issue May 17, 2015 · 7 comments

Comments

@saschagehlich
Copy link

commented May 17, 2015

I get this warning for code like this:

class HeaderComponent extends React.Component {

}

But the JSX in Depth article states:

JSX will infer the class's displayName from the variable assignment when the displayName is undefined

So I guess this rule should be disabled?

@feross

This comment has been minimized.

Copy link
Member

commented May 17, 2015

What warning do you get? Please run standard with the --verbose flag to get the rule name.

@saschagehlich

This comment has been minimized.

Copy link
Author

commented May 17, 2015

BPMComponent component definition is missing display name (react/display-name)

With the following code:

/* global React */
export default class BPMComponent extends React.Component {
  render () {
    return (
      <div></div>
    )
  }
}
@feross

This comment has been minimized.

Copy link
Member

commented May 17, 2015

Do any other react users have an opinion on this?

@feross feross added the question label May 17, 2015

@dcousens

This comment has been minimized.

Copy link
Member

commented May 18, 2015

@feross the displayName can be inferred, but it is also only for debugging. I personally use it very rarely because I already have source maps for my errors anyway, but, I may be the exception.

@RichardLitt

This comment has been minimized.

Copy link
Contributor

commented May 18, 2015

I get the error for this if I don't include displayName. I find the error useful, but my syntax seems different than yours.

var React = require('react')

module.exports = React.createClass({
  displayName: 'Alert',
  propTypes: {
    data: React.PropTypes.string
  },
    render: function () {
    return (
      <div>
        {typeof this.props.data === 'string' ?
        <button type="button" className="btn btn-warning btn-full">
        {this.props.data}
        </button>
        : ''}
      </div>
    )
  }
})
@cayuu

This comment has been minimized.

Copy link

commented May 29, 2015

The example provided by @RichardLitt is the use-case where having a warning show up is useful if you haven't declared displayName.

All other "normal" workflows (shown by the others in this thread) are valid/idiomatic, and do not warrant even a 'warning' (let alone an error). As @dcousens says, declaring displayName is a debugging tool.

For now, get back to the greenlight by adding displayName (this not idiomatic, it's extra code and in all cases except creating anonymous classes, it's completely unnecessary):

export default class BPMComponent extends React.Component {
  get displayName () { return 'BPMComponent'; }
  // ...
}

+1 to remove this as an error.

@feross

This comment has been minimized.

Copy link
Member

commented May 30, 2015

If someone sends a PR for this, I'll merge it.

@dcousens dcousens closed this Jun 11, 2015

@lock lock bot locked as resolved and limited conversation to collaborators May 11, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
5 participants
You can’t perform that action at this time.