Home > database >  React: TypeError Cannot read properties of undefined (reading '0')
React: TypeError Cannot read properties of undefined (reading '0')

Time:10-30

I am working on a React App, and i'm trying to get some data using an enter image description here

CodePudding user response:

If you use optional chaining (?.) to catch possible null/undefined values, you'll most likely fix the issue.

So like this: let res = response.data.data?.[0];

  • Related