【发布时间】:2022-01-24 08:14:13
【问题描述】:
我已经用 Firebase 版本 9 更新了我的项目,但我开始遇到一些我仍然无法解决的代码错误。
之前的函数是这样的。我需要为新的 firebase V9 版本更新它
const doc = await firebaseApp
.firestore()
.collection('documents')
.doc(params.documento)
.get();
if (!doc) {
return {
notFound: true,
};
}
const data = doc.data();
return {
props: {
texto: {
...data,
fecha: data?.fecha?.toDate().toLocaleString('es-ES', { timeZone: 'UTC', day: '2-digit', month: 'long', year: 'numeric' }),
},
},
};
}
【问题讨论】:
-
与其发布您的 V8 代码并仅仅要求别人为您将其翻译成 V9,最好展示您对 V9 代码的尝试,然后描述您遇到的错误。
-
Firebase documentation 有 v8 和 v9 语法的代码示例,因此您可以比较它们,upgrade guide 也概述了该过程。
-
是的,错误是 A required parameter (documento) was not provided as a string in getStaticPaths for /documento/[documento] 当前代码是 `export const getStaticPaths = async () => { const快照 = 等待 getDocs (collection(db, 'documents')); const paths = snapshot.docs.map(doc => { return { params: {id: doc.id.toString()} } }) return { paths, fallback: false } } `
标签: javascript reactjs firebase google-cloud-firestore next.js