我從我的 firestore 資料庫中獲取資料,如下所示:
const [songs, setSongs] = useState();
async function getSongs() {
const songs = collection(db, 'songs');
const songSnapshot = await getDocs(songs);
const songList = songSnapshot.docs.map(doc => doc.data());
setSongs(songList);
console.log(songList);
console.log(songs);
};
如果我跑這一點,有在控制臺的兩個物件,第一個是的SongList,而第二個是歌曲:

為什么兩者之間存在差異?我該怎么做才能將歌曲變回陣列?
uj5u.com熱心網友回復:
"songs"是一個CollectionReference并且不包含資料。"songList"是一個陣列,其中包含來自getDocs(). 你應該設定songList在你的狀態而不是songs
從檔案中,
CollectionReference 物件可用于添加檔案、獲取檔案參考和查詢檔案(使用 query())。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/334744.html
標籤:javascript 反应 火力基地 谷歌云firestore
