I want to wrap a ReactJS component with div, but I want to wrap the elemnt every 5 items only. I've managed (with little help) to add line break every 5 items.
here's the code:
var Item = React.createClass({
render: function() {
return <span> {this.props.num}</span>;
}
});
var Hello = React.createClass({
render: function() {
var items = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ];
return <div>{items.map(function (i,index) {
if (index % 5 === 0) {
return [ <br />, <Item key={i} num={i} /> ];
}
return <Item key={i} num={i} />;
})}</div>;
}
});
ReactDOM.render(
<Hello name="World" />,
document.getElementById('container')
);
here's a JSFIDDLE
i still want to use the .map function to loop through the array, it is more convenient and intuitive.
the question is how do I wrap it with a <div> and not <br> every 5 lines?
sorry for the confusion here is an explanation: wanted:
<div>0 1 2 3 4</div>
<div>5 6 7 8 9</div>
what I have:
0 1 2 3 4 <br />
5 6 7 8 9 <br />