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
e87108a892
commit
191d87662d
|
@ -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];
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue