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

108
Vistas
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
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