Skip to content

Instantly share code, notes, and snippets.

@abhi9bakshi
Last active March 15, 2019 07:48
Show Gist options
  • Save abhi9bakshi/90516b5da581fed3c25437d3f8bb39c8 to your computer and use it in GitHub Desktop.
Save abhi9bakshi/90516b5da581fed3c25437d3f8bb39c8 to your computer and use it in GitHub Desktop.
React Redux

To use redux, we must first import it

const redux = require('redux');

In redux we have a central store to store data

const data = {
  counter: 0
}
const store = redux.createStore(data);

We also need a reducer to update data to central store

const reducer = (state = data, action) {
  // Some action here
}

We subscribe to the instance of store wherever we need access to global store

store.subscribe((e) => {
  // some action here
});

We dispatch actions which goes by reducer to the store

store.dispatch({ key: value });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment