Creating a reducer

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:

  1. We'll start by importing the Reducer type from Redux, along with the combineReducers function:
import {   Action,   ActionCreator,   Dispatch,   Reducer,   combineReducers } from 'redux';
  1. 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 ...

Get ASP.NET Core 3 and React now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.