Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
Uncaught TypeError: Cannot read properties of undefined (reading 'dailyconfirmed')

what's problem with my code i am getting error while accesing mydata.dailyconfirmed after page reloading?

 const[state,setState]=useState({});
async function getApiIndia1(){
   const temp=await fetch('https://data.covid19india.org/data.json')
   const mydata=await temp.json();
   setState(mydata)
}
useEffect(() => {
    getApiIndia1();
}, [])
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Update the setState

setState(mydata.cases_time_series)

and when you wish to find dailyconfirmed, loop over your state which is basically an array of object.

state.map((dailyconf)=>{
if(dailyconf?.dailyconfirmed) console.log(dailyconf?.dailyconfirmed)
})
about 4 years ago · Juan Pablo Isaza Report

0

You cannot access mydata outside of getApiIndia1 (which I assume you are trying to do). It is only defined in that block, which is the reason why you're using state (essentially to save the required data globally). mydata can't be found and that's why it's throwing an error. What you should do instead is access state, which is where you're storing that data.

But that will still throw an undefined. That's because of the issue that previous answers have already highlighted. You need to access state.cases_time_series.dailyconfirmed. That should give you the data you want.

It's always a good idea to check API responses carefully. ;)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!