【发布时间】:2021-11-09 13:10:25
【问题描述】:
我正在为一个项目开发 react + firestore 9,并且我一直在寻找一种检索数据以显示在我的应用程序上的方法。事情是我看到很多人推荐这种语法:
import firebase, { db } from 'path/to/firebase';
import {collection, getDocs, getDoc, query, doc, addDoc, deleteDoc, updateDoc} from "firebase/firestore";
// CONSULTA
const result = await getDocs(query(collection(db, 'persons')));
我的问题是关于异步函数外部的等待,我总是遇到同样的错误,我通过创建一个异步函数来包装等待,如下所示:
import firebase, { db } from 'path/to/firebase';
import {collection, getDocs, getDoc, query, doc, addDoc, deleteDoc, updateDoc} from "firebase/firestore";
// CONSULTA
const result = async() => {
const foo = await getDocs(query(collection(db, 'persons')));
};
所以;我可以做些什么让它在异步函数之外工作,还是我注定要永远将等待包装在异步函数中?
【问题讨论】:
标签: javascript reactjs firebase asynchronous google-cloud-firestore