I have this JSON data I am trying to render as a list.
[{
"id": "1",
"name": "Bill"
}, {
"id": "2",
"name": "Sarah"
}]
I am trying to display the data such that I pass a title of the data and the id's as parameters from Parent class to Child class and the latter prints the data as list.
export default class Parent extends Component {
render() {
return (
<div>
<Child
title={"Group 1"}
options={this.props.data.name}
/>
</div>
);
}
}
Here's my Child class:
export default class Child extends Component {
render() {
var data=this.props;
var title=this.props.title;
var name=this.props.name;
return (
<ul>
<h4>{title}</h4>
<div>{this.props.map(item=>
<li>{name}</li>
)}
</div>
</ul>
);
}
}
What I don't understand is how to use map in the Child class to display data. I know that I shouldn't write this.props.map(item=>
. I am new to React and would appreciate some help fixing this.