I have a long list of items in an array. These need to be rendered in a component, which should be all fine and dandy. However, I need these to be wrapped by another component at every 3 items.
So, if I were to just render the items it would look like this:
return (
<div>
items.map((x, index) => {
<span key={index}>{x}</span>
})
</div>
)
But basically, I want every three items to be wrapped inside a div with a special class, so something like this:
return (
<div>
<div className='group-of-3'>
<span>Item 1</span>
<span>Item 2</span>
<span>Item 3</span>
</div>
<div className='group-of-3'>
<span>Item 4</span>
<span>Item 5</span>
<span>Item 6</span>
</div>
.
.
.
</div>
)
What would be the ideal way to do this? Keep in mind that the amount of items does change, so doing it manually is out of the question.