The time has come to implement state in the HomePage component so that we can store any unanswered questions. But how do we do this in function-based components? Well, the answer is to use another React hook called useState. Follow the steps listed in HomePage.tsx to do this:
- Add the useState hook to the React import and the QuestionData interface to the QuestionsData import:
import { useEffect, useState } from 'react';...import { getUnansweredQuestions, QuestionData } from './QuestionsData';
- We'll use this hook just above the useEffect statement in the HomePage component to declare the state variable:
const [questions, setQuestions] = useState<QuestionData[] | null>(null);useEffect(() ...