The api response i get back has 10 objects of people inside it and i would like react to display the Persons name and gender. I'm not sure how to accomplish this. Is states even the right way to go about this or should i try to save my response inside of an array only?
Any help is appreciated.
state = {
Person: null,
Gender: null
}
async componentDidMount() {
const url = "**********************************************";
const response = await fetch(url);
const data = await response.json();
this.setState({Person: data[0].Name})
this.setState({Gender: data[0].Gender})
}
render() {
return <div>
<p>
{this.state.Person}
</p>
<p>
{this.state.Gender}
</p>
}
}