Perfection Perfection - 1 month ago 6
ASP.NET (C#) Question

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.

Answer

Add the displayName property to your components:

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