我正在關注一個教程,并且在代碼中使用了 firebase.firestore.FieldValue.serverTimestamp() 來將timestampprop設定為服務器時間戳。
import firebase from "firebase";
const someFunction = () => {
addDoc(collection(db, `rooms/${roomId}/messages`), {
message: input,
name: user.displayName,
timestamp: firebase.firestore.FieldValue.serverTimestamp(),
}).then((res) => getMessagesData());
};
但我收到這個錯誤。
Module not found: Can't resolve 'firebase' in ...
我想 firebase 有某種更新,我們不再匯入它import firebase from "firebase";了嗎?我應該怎么做才能使用servertimestamp()?
uj5u.com熱心網友回復:
有關最新示例,請參閱有關添加服務器端時間戳的檔案,其中包含此代碼段
import { updateDoc, serverTimestamp } from "firebase/firestore";
const docRef = doc(db, 'objects', 'some-id');
// Update the timestamp field with the value from the server
const updateTimestamp = await updateDoc(docRef, {
timestamp: serverTimestamp()
});
該檔案包含新的 v9 模塊化語法和您可能在許多第三方教程中找到的舊語法的并排示例,因此您可以查找如何將代碼轉換為新語法。該升級指南是開始使用,太多的好辦法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/335937.html
標籤:javascript 反应 火力基地 谷歌云firestore 时间戳
