Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda