I have updated my project with version 9 of firebase and I started to have some code errors that I still can't solve.
the previous function looks like this. and I need to update it for the new firebase V9 version
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' }),
},
},
};
}
I found a way to solve this problem.
const snapshot = await getDocs (collection(db, 'documents'));
const paths = snapshot.docs.map(doc => {
return {
params: {
documento: doc.id.toString()
}
}
})
return {
paths,
fallback: false
}
}
export const getStaticProps = async (context) => {
const documento = context.params.documento;
const docRef = doc(db, 'documents', documento);
const docSnap = await getDoc(docRef);
return {
props: {textoProps: JSON.stringify(docSnap.data()) || null}
}
}