import firestore from "./firebase";
import { doc, type DocumentData, getDoc } from "@firebase/firestore";
var fontData : DocumentData | undefined
const fontDoc = doc(firestore, "fl_content", "Cql65iKgsQ7NIaF3gUNe")
console.log('fontDoc',fontDoc)
const fontDocData = getDoc(fontDoc);
console.log('fontDocData',fontDocData)
fontDocData.then((value) => {
console.log('fontValue',value)
fontData = value.data()
console.log('fontData',fontData)
})
console.log('afterfontData',fontData)
Above is the code I wrote to get data from a firebase document. Since this is purely a Typescript file and I am writing this code at the top-level, I couldn't use await, hence, I resolved the Promise using the then
statement. Now I would like to access the value outside of the then block, but I couldn't access it even though I assigned to a variable. Is there any workaround for this ?
As you can see the console.log returns the intended value inside the then block, but outside of it, it returns undefined.