
我有一個 Firebase 資料庫,其中包含白名單的以太坊地址。我是初學者,我剛開始使用fireBase。我做了很多研究,但我陷入了困境。我將檢索資料庫中的所有地址,并使用 React JS 中的 usestate 將它們存盤在一個陣列中。
非常感謝
uj5u.com熱心網友回復:
如果您有錯誤說集合、getDocs、db 未定義...嘗試使用“@”匯入它。
我是說:
import { collection, getDocs } from "@firebase/firestore"
import { db } from "@lib/firebase"
uj5u.com熱心網友回復:
import { collection, getDocs } from "firebase/firestore";
import { useState } from "react";
const [state,setState] = useState([])
const querySnapshot = await getDocs(collection(db, "nameOfYourCollection"));
querySnapshot.forEach((doc) => {
setState(prevState=>[...prevState,doc.data()])
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/486756.html
