I'm trying to fetch data from firebase. I want to push the values in an array and map through it in a view. The only problem is that i can see the values in my array but not outside the .then function.
const dataArray = []
firebase
.database()
.ref("Challenges/Day")
.once("value")
.then((snapshot) => {
snapshot.forEach((child) => {
dataArray.push(child.val());
});
console.log(dataArray)
});
return (
<View style={styles.text}>
{dataArray.map((data) => {
<Text>{data}</Text>;
})}
</View>
);
if i console log it then the output is : Array [ "eat", "sleep", ] But outside it's function my array is empty.