ReactJS - How can I access the displayName of a component using javascript?

javascript, reactjs

Solution

It's available as the public property `this.constructor.displayName`.

Problem

I'm building some React components and sometimes would like to log to the console the type of component that's being rendered, by `displayName`, which JSX uses when displaying the name of a component. From the context of a component, how can I access the `displayName` property? e.g. how can I make the `console.log` statement in this example show the displayName of the component? ``` var Hello = React.createClass({ displayName: 'HeyHey', render: function() { console.log(this.displayName); return <div>Hello {this.props.name}</div>; } }); ``` Intended output in console: HeyHey

Original source