How to render react components by using map and join?

后端 未结 14 2199
南旧
南旧 2020-12-07 15:30

I have one component which is going to display Array of String. The code looks like this:

React.createClass({
  render() {
     
this.props
14条回答
  •  悲哀的现实
    2020-12-07 15:54

    Using es6 you could do something like:

    const joinComponents = (accumulator, current) => [
      ...accumulator, 
      accumulator.length ? ', ' : '', 
      current
    ]
    

    And then run:

    listComponents
      .map(item =>  {item.t} )
      .reduce(joinComponents, [])
    

提交回复
热议问题