Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rid of repeated spans in React.js?

Tags:

reactjs

React renders multiple spans, only with the actual value. Any advice on how to fix this:

enter image description here

And if it matter, the name of the user isn't suppose to be in a span, but as innerHTML of ".chatUser"

The actual render method is short:

createShortUsername: function() {
 // shortName is first two letter of first name. 
 var shortName = this.props.userName.split(" ")[0].slice(0, 2);
 console.log(shortName);
 return shortName;
},
render: function() {
 return (
   <div className="chatUser"> {this.createShortUsername()} </div>
 );
}

Thanks!

like image 353
kaid Avatar asked Oct 22 '14 06:10

kaid


1 Answers

As suggested by @ivarni, the extra spans were caused by white spaces!

To prevent this write your code without white spaces around the braced expressions.

<ReactElement>{noRoomForWhiteSpace}</ReactElement>
like image 188
kaid Avatar answered Sep 20 '22 02:09

kaid