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 !