Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

Uncaught TypeError: Cannot read properties of null (reading '0') when fetch the API link in react.js ?

By M.K. Verma · 2 May 2022

Uncaught TypeError: Cannot read properties of null (reading '0') when fetch the API link in react.js ?

As receiving api response and setting state is asynchronous, you need to check that the state datas is not undefined, just change the line to:

if(datas && datas.length>0)
   console.log(datas[0]);