Search code examples
asp.netreactjsecmascript-5

How do you give components a name in react?


When I am debugging using the browser console console or react dev tools, they always refer to my components as "Constructor" and I would like to change that. See the example below:

Example error message

I would have hoped to set defined names for my components so they would show up as "MyComponent" for example. This would help on pages where there are many components and one of them is throwing a warning that I would like to solve.


Solution

  • Add the displayName property to your components:

    var Component = React.createClass({  
      displayName: 'MyComponent',
      ...
    });