Answer the question
In order to leave comments, you need to log in
Correct array rendering in react - how to do it?
I'm learning React, writing a test project for myself.
And now I ran into a problem: there is a string of tags listed separated by commas, I use .map() to split it into an array and scatter each tag into a link
. And I just can’t figure out how to put a comma with a space after the link. How can this be done without wrapping it in a separate container?
It is also interesting: is it adequate to render such elements in this way at all? Later, of course, not a string, but an array of tags will come, but this is another topic.
Answer the question
In order to leave comments, you need to log in
While I decided with such a crutch
this.props.tags.split(',').map((tag, i) =>
<span key={i}>
<a className="tag">{tag}</a>
{i === this.props.tags.split(',').length -1 ? '' : ', '}
</span>
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question