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