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

master
Jason Zhu 2022-03-30 14:04:55 +11:00
parent 1f7388e26d
commit 3fb4435d68
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> => { const wait = (ms: number): Promise<void> => {
return new Promise((resolve) => setTimeout(resolve, ms)); 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];
};