Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A sample of getStaticProps
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