Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda