Creating the state
In this section, we are going to implement the type for the state object in our store, along with the initial value for the state. Perform the following steps to do so:
- Create a new file called
Store.ts
in thesrc
folder with the followingimport
statement:import { QuestionData } from './QuestionsData';
- Let's create the TypeScript types for the state of our store:
interface QuestionsState { Â Â readonly loading: boolean; Â Â readonly unanswered: QuestionData[]; Â Â readonly viewing: QuestionData | null; Â Â readonly searched: QuestionData[]; } export interface AppState { Â Â readonly questions: QuestionsState; }
So, our store is going to have a
questions
property that is an object containing the following properties:loading
: Whether a server request is being madeunanswered
: An array containing unanswered questionsviewing
: The question the user is viewingsearched
: An array containing questions matched...