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

135
Views
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
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!