How to loop and render elements in React.js without an array of objects to map?

前端 未结 5 1683
轻奢々
轻奢々 2020-11-28 01:35

I\'m trying to convert a jQuery component to React.js and one of the things I\'m having difficulty with is rendering n number of elements based on a for loop.

I un

5条回答
  •  攒了一身酷
    2020-11-28 02:03

    Array.from() takes an iterable object to convert to an array and an optional map function. You could create an object with a .length property as follows:

    return Array.from({length: this.props.level}, (item, index) => 
      
    );
    

提交回复
热议问题