I am trying to create nested lists in separate div's
using different input data. I am having a problem printing a nested list: List 2
here. I printing the name
attribute of object and then checking if there are any childNodes
print the name
attribute of those too, nested that is. Here's the Parent
class.
export default class Parent extends Component {
render() {
return (
<div>
<h4>List 1</h4>
<ul>
{this.props.jsonData1.map(item => {
return <Child name={item.name}/>
})}
</ul>
</div>
<div>
<h4>List 2</h4>
<ul>
{this.props.jsonData2.map(item1 => {
return <Child name={item1.name}/>
if(item1.childNodes){
<ul>
{item1.jsonData2.map(item2=>{
return <Child name={item2.name}/>
})}
}</ul>
})}
</ul>
</div>
);
}
}
My Child
class is pretty simple. It only returns a single list element.
export default class Child extends Component {
render() {
let {name}=this.props;
return (
<li>{name}</li>
);
}
}
I would appreciate some guidance about what I am doing wrong here. I am trying to keep the recursion as simple as possible but apparently I am doing it wrong.