I want to make a list of fields depending on the number of the player that user has selected. I wanted to make something like this:
generatePaymentField() {
You can create render the results (payments) and use a fancy way to iterate over items instead of adding a for loop.
const noGuest = 3;
Array(noGuest).fill(noGuest).map(guest => {
console.log(guest);
});
Example:
renderPayments(noGuest) {
return Array(noGuest).fill(noGuest).map((guess, index) => {
return(
);
}
}
Then use it where you want it
render() {
return(
const { guest } = this.state;
...
{this.renderPayments(guest)}
);
}
Hope you got the idea.
If you want to understand this in simple Javascript check Array.prototype.fill()