I'm working on react + firestore 9 for a project and i've been looking at a way of retrieving data to display on my application. Thing is I see a lot of people recommending this syntax:
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')));
My question is about the await outside an async function, I allways get the same error that I solve by creating an async function to wrap the await like so:
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')));
};
So; is there something I can do to make it work outside the async function, or am I doomed for eternity to wrap awaits in async functions?