I have a problem accessing information from an array that has an object inside, using React.
This is the function that brings my json and changes the state of the application, it creates a times.name, times.players and times.foto, in case this will turn an array of objects
getTimes () {
ajax().get('./src/json/times.json')
.then(result => {
this.setState({
times: result.map((time) => ({
nome: time.time,
players: time.player,
fotos: time.foto
}))
})
})
}
Here I move it to my app-content
render() {
return <AppContent
times={this.state.times}
/>
}
In it, I render my component
<TimeCasa times= {times} />
So far so good, but there in my component
const TimeCasa = ({times}) => {
let pos = times[0]
console.log(pos)
return (
<div className='wrapper-casa'>
<h1 className="time">{pos.nome}</h1>
times [0] finds the object normally and I assign it to the variable pos, within that variable I called the pos.name and it of the error saying that it is not possible to access name of undefined, being pos is not undefined, it is an object that contains the key name. Does anyone know what it can be?