I am getting data like this from my firebase collection:
Object {
"data": Object {
"valuesArray": Array [
"MCU",
"Anime",
"Shopping",
"Travelling",
"Cooking",
],
},
}
I want to store valuesArray
in a bigger state object in react such as this:
const [data, setData] = useState<any>({});
The idea is that I store each data collection in this big state data object. I am finding it hard to reach the valuesArray
since the data received has Object
, then data
, then Object
again.
How can I accomplish storing only the valuesArray
in the big state object?
I got there in the end by extracting the valuesArray right on the async function:
const createCategoriesArray: any = async () => {
await db
.collection("categories")
.get()
.then(querySnapshot => {
return querySnapshot.docs.map(doc => {
return {
data: doc.data().valuesArray,
};
});
})
.then(data => {
setCategories(data);
})
.catch(error => {
console.log("Error getting documents: ", error);
});
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.