Implementing more of the question page

Let's carry out some more steps to implement the question page a little more:

  1. 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.

  1. Moving on to QuestionPage.tsx, let's import the function we just created, along with the question interface:
import { QuestionData, getQuestion } from './QuestionsData';
  1. We are going to store the question in the state when the ...

Get ASP.NET Core 3 and React now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.