In this section, we are going to implement a reducer, which is responsible for changing the state in the store for a given action. Let's carry out the following steps:
- We'll start by importing the Reducer type from Redux, along with the combineReducers function:
import {
Action,
ActionCreator,
Dispatch,
Reducer,
combineReducers
} from 'redux';
- Let's create the skeleton reducer function:
const questionsReducer: Reducer<QuestionsState, QuestionsActions> = (
state = initialQuestionState,
action
) => {
// TODO - Handle the different actions and return new state
return state;
};
The reducer takes in two parameters: one for the current state and another for the action that is being processed. The state will be undefined the first time the reducer is called, so we default this to the initial state we created earlier...