Due to repeated intervals in React.js?

React displays multiple intervals, only with the actual value. Any tips on how to fix this:

enter image description here

And if that matters, the username should not be in the span, but like innerHTML in .chatUser

The actual rendering 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!

+5
source share
2 answers

As suggested by @ivarni, extra spaces were caused by spaces!

To avoid this, write your code without spaces around the brackets.

 <ReactElement>{noRoomForWhiteSpace}</ReactElement> 
+10
source

In fact, some special characters (not visible in your editor) that penetrate the code. (Probably if you copied). For me it was \u2028 . Check the generated javascript file to see what extra characters are in the code. To get rid of it, you can delete the line that called it and type it again (as opposed to copy and paste).

0
source

Source: https://habr.com/ru/post/1205253/


All Articles