I'm having trouble developing a clean solution to rendering multiple child components from inside a container component.
I have a Store object in the following schema:
{
"events": {
"2017": {
"March": {
"event1": {
"type": "concert"
},
"event2": {
"type": "hockey"
}
}
},
"2018": {
"January": {
"event3": {
"type": "basketball"
}
}
}
}
}
I'd like the output to be formatted
<section>
<ul><span>March 2017</span>
<li>event1 - concert</li>
<li>event2 - hockey</li>
</ul>
<ul><span>January 2018</span>
<li>event3 - basketball</li>
</ul>
</section>
My initial thought was to iterate through each layer from the parent/container component's render method, starting with:
class Events extends Component {
render() {
let key = 0
return (
<section>
Object.keys(this.props.events).map(year => {
/* continue iterations and build JSX here */
})
</section>
)
}
}
But mapping three levels deep isn't very elegant this way, not to mention, I'm having trouble maintaining compliant JSX.
Is parsing this object into several presentational components, having each child component handle iteration at its own level the best way to approach this? If so, would I pass each layer of the object (ie: year, month) down as a prop?