1

I installed chrome react developers tool, which I have been using for some days now. It's very handy one can see the React components name's through the chrome react tool. I have been wondering why for some of my components, the chrome developer tool transforms the name of the components as 'StatelessComponent'. It would be nice to have the real component's name there, instead of 'StatelessComponent'.

I wonder why it shows it like that? I did read something about using stateless components in react is a good practice, but I'm not sure if that is wanted in my case. Can anyone explain why does chrome react tools transform the name to StatelessComponents? There must be an important reason for it.

2 Answers 2

2

Found a solution:

Chrome react dev tools labels them as stateless components if you have not set the displayName like this:

Component.displayName = "ComponentName"

You have to set the displayName like this if you are creating your react components with this style:

ReactComponent = (props) ->
Sign up to request clarification or add additional context in comments.

Comments

0

Here you've two options:

Option 1

const Button = ({name}) => (<button>{name}</button>);
Button.displayName = 'Button';

Option 2

function Button({name}) {
  return (<button>{name}<button>);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.