In componentDidMount (), I get the data and pass it to the state.
componentDidMount() {
const url = fetch('http://localhost:8000/posts/')
.then(response => response.json())
.then(response => {
this.setState({ data: response });
})
}
Next I try to get the data of this.state.data[0].id
In this case, I get the error
TypeError: cannot read property 'id' of undefined
But if I try to get data through this.state.data[0], then an object comes in, where there is a property id
this.state.data[0].id? Is it in yourrender()function?