I'm new to ReactJS. And somehow, I find my codes awful If I wouldn't do something about the redundancies. My array had one hundred items. And mapping them costs too much lines. Given the class, my code looks like this:
{
"lists": [
{
"item1": "Lorem",
"item2": "Lorem",
"item3": "Lorem"
}, {
"item1": "Lorem",
"item2": "Lorem",
"item3": "Lorem"
}, {
"item1": "Lorem",
"item2": "Lorem",
"item3": "Lorem"
}, //...couple dozens more
]
}
render(){
const lists = this.state.lists
const list_a = lists.map((lists, i) => {
return (
<div key={i}>
<div>
<div>
<div>
<span>{lists.item1}</span>
<span>{lists.item2}</span>
<span>{lists.item3}</span>
</div>
</div>
</div>
</div>
)
}).slice(0, 5)
const list_b = lists.map((lists, i) => {
return (
<div key={i}>
<div>
<div>
<div>
<span>{lists.item1}</span>
<span>{lists.item2}</span>
<span>{lists.item3}</span>
</div>
</div>
</div>
</div>
)
}).slice(5, 10)
const list_b = lists.map((lists, i) => {
return (
<div key={i}>
<div>
<div>
<div>
<span>{lists.item1}</span>
<span>{lists.item2}</span>
<span>{lists.item3}</span>
</div>
</div>
</div>
</div>
)
}).slice(10, 15)
}
As you can see, it looks ridiculous. Is there a way where I can somehow manipulate slice like ".slice(0, n)" or something like that?