Chap05 -> Using route parameters -> Implementing more of the question pagee -> 1. Add a function that will simulate a web request to get a question

Chap05
Jason Zhu 2022-03-30 14:04:55 +11:00
parent e87108a892
commit 191d87662d
1 changed files with 8 additions and 0 deletions

View File

@ -56,3 +56,11 @@ export const getUnansweredQuestions = async (): Promise<QuestionData[]> => {
const wait = (ms: number): Promise<void> => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
export const getQuestion = async (
questionId: number,
): Promise<QuestionData | null> => {
await wait(500);
const results = questions.filter((q) => q.questionId === questionId);
return results.length === 0 ? null : results[0];
};