在Next.js 13中获取Firestore文档

fzsnzjdm  于 2023-06-22  发布在  其他
关注(0)|答案(1)|浏览(87)

我是React/NextJS新手,我试图从Firestore Collection中获取文档列表,在SSR页面中使用Next JS 13,以便在下面列出它们。
我可以从我的函数中获取文档,但是,我不知道如何将它们放入页面,以便我可以列出它们。

我的代码

import { FIREBASE_FIRESTORE } from "../../configuration/firebase";
import { collection, getDocs } from "firebase/firestore";

async function getCustomers() {
  const customers = await getDocs(collection(FIREBASE_FIRESTORE, "customer"));

  // I CAN GET DOCUMENTS HERE
  const data = customers.docs.map((doc) => {
    console.log(doc.data());
  });
}

export default async function CustomersPage() {
  const customers = getCustomers();
  // BUT HOW DO I GET THEM HERE???

  return <></>;
}

任何帮助非常感谢。

eanckbw9

eanckbw91#

没有在功能范围内回复我的客户。真他妈的

async function getCustomers() {
  const customers = await getDocs(collection(FIREBASE_FIRESTORE, "customer"));
  return customers;
}

相关问题