-
-
Save RyotoNoguchi/a05caaf251ff46cfff479780a7953716 to your computer and use it in GitHub Desktop.
A sample of getStaticProps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GetStaticProps, GetStaticPropsContext } from 'next' | |
import { ParsedUrlQuery } from 'querystring'; | |
const db = firebase.firestore() | |
type Choices = { | |
A: string | |
B: string | |
C: string | |
D: string | |
} | |
type QuestionType = { | |
id: string | |
question: string | |
answer: string | |
choices: Choices | |
} | |
export const getStaticProps: GetStaticProps<QuestionType> = async (context: GetStaticPropsContext<ParsedUrlQuery>) => { | |
const id = context.params.id; | |
const querySnapShot = await db | |
.collection('questions') | |
.where('questionId', '==', id) | |
.get(); | |
const question = querySnapShot.docs[0] | |
return { | |
props: { | |
id: question.data().questionId, | |
question: question.data().question, | |
answer: question.data().correctAnswer, | |
choices: question.data().choices, | |
}, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment