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