Installing and Using Redux

We first need to install Redux, the Redux bindings for React, and their associated type definitions:

 $ yarn add redux react-redux @types/redux @types/react-redux

Then, we’ll create a Redux store in our app.

Creating a Redux Store

To create a store in our app, we’ll use the function provided by Redux called createStore, which takes a reducer function as its one argument. (There’s a Redux Toolkit library that has support for creating more complex stores and reducers. We won’t be using it in this book, but if you are building true single-page applications with Redux, you should definitely look at it.)[83]

The reducer we’ve been building in our page so far is almost exactly structured to work in Redux as is. The main ...

Get Modern Front-End Development for Rails 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.