Chap05 -> Using route parameters -> Implementing more of the question pagee -> 1. Add a function that will simulate a web request to get a question
parent
1f7388e26d
commit
3fb4435d68
|
@ -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];
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue