D
D
Denis Bukreev2017-05-10 22:45:39
React
Denis Bukreev, 2017-05-10 22:45:39

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
251eb6f2dbb04b3aa570cf3244686d4f.png
. 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

1 answer(s)
D
Denis Bukreev, 2017-05-10
@denisbookreev

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 question

Ask a Question

731 491 924 answers to any question