Print something x number of times in JSX / ReactJS
If you are using ReactJS you might be asking how to print something x number of times.
plain characters there are many ways to do this such as
let stars = "*".repeat(this.props.review.rating) //where rating is 5
this doesn’t work in when you start using elements as the subject of repetition
for the code:
let newstars = .repeat(this.props.review.rating)
this is the error
TypeError: __WEBPACK_IMPORTED_MODULE_0_react___default.a.createElement(…).repeat is not a function
The fix is to add items the following way:
let newstars = []
for(let i=0;i<this.props.review.rating;i++){
stars.push()
}
//now display the JSX as such in your return
{newstars}