I am having problems with this logic, since response / jsx does not allow adding non-blocking tags to the array / child component. For example, using bootstrap css, I want to add a row for each 4 columns.
So the logic is this:
Add the starting line ex:, <div className="row">then loop inside that line, and each loop adds an ex: column <div className="column>{this.data}</div>when the loop reaches 4 with if(i % 4 == 0)and adds a closing tag </div>when adding a new line tag <div className="row">;
The code below will work in another language, but in response this is not feasible, because we click on the closing tag and the opening tag (which is not valid jsx):
generateColumns(columns) {
let newColumns = [];
columns.forEach(function(column, idx) {
newColumns.push( <div className="column"> some data </div> );
if (idx % 4 == 0) {
newColumns.push( </div> <div className="row"> );
}
});
return newColumns;
},
render() {
return (
<div className="row">
{this.generateColumns(this.props.columns)}
</div>
)
}
Expected Result:
<div class="row">
<div class="column">
Some data
</div>
<div class="column">
Some more data
</div>
<div class="column">
Other data
</div>
<div class="column">
Something else
</div>
</div>
<div class="row">
<div class="column">
Some data
</div>
<div class="column">
Some more data
</div>
<div class="column">
Other data
</div>
<div class="column">
Something else
</div>
</div>
//the above would be repeated and new rows would appear every 4 columns.