Skip to content

Instantly share code, notes, and snippets.

@RyotoNoguchi
Last active December 17, 2021 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyotoNoguchi/a05caaf251ff46cfff479780a7953716 to your computer and use it in GitHub Desktop.
Save RyotoNoguchi/a05caaf251ff46cfff479780a7953716 to your computer and use it in GitHub Desktop.
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