En mi aplicación React Native, obtengo un valor de Firebase usando
this.getRef() .doc(<something>) .collection(<something>) .doc(<something>)Quiero registrar el valor devuelto por eso, pero no sé si devuelve una promesa. me gustaría hacer algo como
let a = this.getRef() .doc(<something>) .collection(<something>) .doc(<something>) console.log(a)¿Cómo debo abordar esto?
Por el momento, solo tiene una referencia al documento, no el documento en sí. Para obtener el documento una sola vez, use .get . Esto devolverá una promesa:
this.getRef() .doc(<something>) .collection(<something>) .doc(<something>) .get() .then(doc => { console.log(doc.data()); }) // Or using async await: const someFunction = async () => { const doc = await this.getRef() .doc(<something>) .collection(<something>) .doc(<something>) .get() console.log(doc.data()); } Alternativamente, si desea continuar escuchando los cambios, use onSnapshot :
const unsubscribe = this.getRef() .doc(<something>) .collection(<something>) .doc(<something>) .onSnapshot(snapshot => { console.log(snapshot.data()); }); // Later you can call unsubscribe() to stop listening