1

this code works

the code works fine but when I try to access the first index it says "cannot read properties of undefined (reading '0')"

this code doesn't work

this is the response of console.log("Dataa", this.state.data.videos)

response

this is the response of console.log("Dataa", this.state.data.videos[0])

enter image description here

1 Answer 1

2

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])
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.