I am fetching some docs from firebase and then want to copy the docs to another array. But it copies the empty array before firebase finish updating the first array.
const [docs, setDocs] = useState()
const [docsCopy, setDocsCopy] = useState()
db.collection('docs').get()
.then(async snap=>{
setDocs(snap.data().map(doc=>{
return doc.name
}))
console.log(docs)
setDocsCopy(docs)
})
console.log also executing before setDocs().
Plz suggest a solution using async and await