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

145
Visualizações
React Array is undefined after loading -> Cannot read properties of undefined

Im new in react and i want to load some data from my example database but every time i load the starting page, i got this error. i dont know why my arrry should be undefined. does someone has an answer for me in this case? im struggeling over hours with it. im working with the newest version of react. i deleted the url of my database because its private. at the end you can see the errormessage and the database structure

here is my code:

import { useState, useEffect } from "react";
import GoalList from "../components/goals/GoalList";
function AllGoalsPage() {
const [isLoading, setIsLoading] = useState(true);
const [loadedGoals, setLoadedGoals] = useState([]);
useEffect(() => {
setIsLoading(true);
fetch(
  "my-database"
)
  .then((response) => {
    return response.json();
  })
  .then((data) => {
    const goals = [];
    for (const key in data) {
      const goal = {
        id: key,
        ...data[key],
      };
      goals.push(goal);
    }
    setIsLoading(false);
    setLoadedGoals(goals);
    console.log(goals);
  });
}, []);
 if (isLoading) {
return (
  <section>
    <p>Loading...</p>
  </section>
);
}
return (
<section>
  <h1>All Goals</h1>
  <GoalList goalsList={loadedGoals} />
</section>
);
}
export default AllGoalsPage;

Error Message

database structure

about 4 years ago · Juan Pablo Isaza
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