Sitemap
c0d3r

c0d3r

The Redux Store

1 min readFeb 25, 2016

Store binds 3 principles of redux

  • holds current application state object
  • lets you dispatch actions
  • when created, need to specify reducer to tell how state is updated with actions

Store has three important methods

  1. getState() which returns the current state of the application
  2. dispatch(ACTION) will change the state based on the ACTION dispatched.
  3. subscribe(CALLBACK) will run the CALLBACK any time an action is dispatched. The callback will typically be a ReactDOM.render

How to setup a store?

Get c0d3r’s stories in your inbox

Join Medium for free to get updates from this writer.

First, import createStore using either

import {createStore} from ‘redux’; 

OR

const {createStore} = redux;

createStore takes a reducer as argument. Initialize the store by telling it which reducer to use

const store = createStore(REDUCER)

Now we can access the current state of the application by

store.getState()

and facilitate auto refresh by linking in the render method using

store.subscribe(render)

--

--