the code works fine but when I try to access the first index it says "cannot read properties of undefined (reading '0')"
this is the response of console.log("Dataa", this.state.data.videos)
this is the response of console.log("Dataa", this.state.data.videos[0])
CodePudding user response:
This is because you are trying to get an index of undefined. Before setting the state to data, the state key 'videos' is undefined. You can try in render:
if (this.state.data.videos) {
console.log('Data', this.state.data.videos[0])
}