1
I am consuming via Xios the following JSON: https://randomuser.me/api/? Results=5
When I try to access person.name.title I get the following error:
I can only access the title property when I type like this {pessoa.name && pessoa.name.title
,
Can someone explain to me why?
import React, {Component} from 'react';
import {Card, Col, Button} from 'react-bootstrap';
import api from "../../services/api"
class CardPeople extends Component {
constructor(props){
super(props)
this.state = {
pessoas: [
{
}
]
}
}
async componentDidMount(){
const people_api = await api.get("https://randomuser.me/api/?results=5");
this.setState({
pessoas: people_api.data.results
})
}
render() {
return (
<>
{this.state.pessoas.map((pessoa, index) =>
<Col key={pessoa.gender}>
<p> {pessoa.name && pessoa.name.title}</p><br></br>
</Col>
)}
</>
)
}
}
It was just that, it worked perfectly, thank you very much.
– Wilker De Sena Guedes