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

106
Views
State not rendering first render in useEffect
const [attendance_list1, setAttendanceList1] = useState([]);

useEffect(() => {
  console.log("entered Use ef");
  const db = getDatabase();
  const reference = ref(db, `prezente/${nume_mat}`);
  let aux = {};
  onValue(reference, (snapshot) => {
    const mat = snapshot.val();
    setAllAttendanceDetails(mat);
    aux = mat;
  });

  console.log(aux);
  showAttendance(aux);
}, []);

function showAttendance(){
  let aux = [];
  for (var key in x) {
    if (x.hasOwnProperty(key)) {
      aux.push(x[key]);
    }
  }
  setAttendanceList1(aux);
}

return (
  <View>
    <Text style={{ fontWeight: "bold" }}>Attendance List 1</Text>
    {attendance_list1.map((item, i) => {
      return <Text key={i}>{item}</Text>;
    })}
  </View>
);

Why the attendance_list1 array is not showing at first render ? I guess that the useStates inside the useEffect are slower that the first render.

The onValue function is from firebase,

Can you please help me figure it out ? Thanks in advance !

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!