Member-only story

Redux Library

Jack
2 min readFeb 1, 2021

--

createStore() and connect()

Redux allows us to access ‘props’ throughout our project and have one global state. In this post, we’ll go in depth on createStore() and connect() when implementing Redux.

First, we need to define some things. We need a reducer when using Redux, like the example below.

The reducer is where we update our current state. When called and passed a state and object (‘action’), it returns an updated state. In the example above, we have a switch statement that can add an animal to the state.

Dispatch persists our state changes.

Now when calling dispatch(action: 'ADD_ANIMAL', payload: 'dog') our global state is {animals: [dog]} .

createStore is a way to privitize our global state so we don’t accidentally change in by calling state anywhere in our code.

--

--

Jack
Jack

Written by Jack

Magician, Mathematician, and Software Engineer

No responses yet