Let's carry out some more steps to implement the question page a little more:
- In QuestionsData.ts, add a function that will simulate a web request to get a question:
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];};
We have used the array filter method to get the question for the passed-in questionId.
- Moving on to QuestionPage.tsx, let's import the function we just created, along with the question interface:
import { QuestionData, getQuestion } from './QuestionsData';
- We are going to store the question in the state when the ...