Using a Redux Store
Create and use a Redux store in this lesson.
We'll cover the following
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 course, but if you are building true Single-Page Apps with Redux, you should definitely look at it.
The reducer we’ve been building in our page so far is almost exactly structured to work in Redux as-is. The main difference is in initialization. Our existing reducer derives its initial state from the props passed to the App
component. Redux, on the other hand, requires its reducers to be able to initialize themselves without any input.
Happily, we can adjust our reducer to behave the way React expects with just a few small changes. First, we need to change our initial state to a value, rather than a function, and we also need to change the signature of the reducer function to take the initial state as a default argument:
Get hands-on with 1200+ tech skills courses.