-
NextJS throws "Cannot convert undefined or null to object" error when getServerSideProps used. export function getServerSideProps() {
firebase.firestore().collection('stuff').get()
.then(docs => {
let stuff = [];
docs.forEach(doc => {
stuff.push({
id: doc.id,
...doc.data()
})
if (docs.size === stuff.length) {
console.log(stuff)
return {
props: {
stuff: stuff
}
}
}
})
})
} To ReproduceSteps to reproduce the behavior, please provide code snippets or a repository:
Expected behaviorgetServerSideProps will pass "stuff" array to page props. System information
|
Beta Was this translation helpful? Give feedback.
Answered by
justincy
May 8, 2020
Replies: 1 comment 1 reply
-
The problem here is that you're not actually returning anything from export async function getServerSideProps() {
return firebase.firestore().collection('stuff').get()
.then(docs => {
let stuff = [];
docs.forEach(doc => {
stuff.push({
id: doc.id,
...doc.data()
})
})
return { props:{ stuff }};
})
} or export async function getServerSideProps() {
const docs = await firebase.firestore().collection('stuff').get()
let stuff = [];
docs.forEach(doc => {
stuff.push({
id: doc.id,
...doc.data()
})
})
return { props:{ stuff }};
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Vista1nik
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem here is that you're not actually returning anything from
getServerSideProps()
. The onlyreturn
in the code snippet is inside offorEach()
. You want something like this:or