Creating a reducer
A reducer is a function that will make the necessary changes to the state. It takes in the current state and the action being processed as parameters and returns the new state. In this section, we are going to implement a reducer. Let's perform the following steps:
- One of the parameters in the reducer is the action that invoked the state change. Let's create a union type containing all the action types that will represent the reducer action parameter:
type QuestionsActions = | ReturnType<typeof gettingUnansweredQuestionsAction> | ReturnType<typeof gotUnansweredQuestionsAction> | ReturnType<typeof gettingQuestionAction> | ReturnType<typeof gotQuestionAction> | ReturnType<typeof searchingQuestionsAction> | ReturnType<typeof searchedQuestionsAction>;
We have used the
ReturnType
utility type to get the return type of the action functions.ReturnType...