Home

Awesome

Learning Redux

Just one of the things I'm learning. https://github.com/hchiam/learning

TL;DR: Redux is a predictable state container. My mnemonic of key things to remember: SDAR = Store -> Dispatch -> Action -> Reducer. You can get a quick review on freeCodeCamp.

yarn add redux or npm install --save redux

Key things to remember: const reducer, store = Redux.createStore(combinedReducer), store.dispatch({type: SOME_ACTION}), reducer = (state, action) => {switch (action.type) {...}}

You can store.subscribe(() => { /* some function that runs as a "listener" upon actions */ })

(You can generate a dependency graph with bash show_dep_graph.sh.)

Simple example

https://github.com/hchiam/learning-redux/tree/master/counter-example

Simple example of updating state in a sibling component

https://github.com/hchiam/code-inspiration/commit/53d13d23cbb7fa13b9c95f108be8d2949072db5a#diff-71bf5fe8b337e70fdec5d142f4881d9eR6

(Added redux without adding react-redux.)

Interactive references of combining Redux with React

Helpful example of adding data to redux state container

https://github.com/hchiam/react-jexcel-redux/commit/90db044627780ed6262f5e29bb61a24390a4d4b3

Examples (via CLI or online sandboxes)

https://redux.js.org/introduction/examples/

cd counter-example
npm install
npm start

Extra notes

Reference

https://redux.js.org/introduction/getting-started/

https://redux.js.org/introduction/motivation/

https://redux.js.org/introduction/core-concepts/

https://redux.js.org/introduction/three-principles/

Cartoon guide to Redux: https://code-cartoons.com/a-cartoon-intro-to-redux-3afb775501a6

Further reading: "5 types of state" (for React apps)

http://jamesknelson.com/5-types-react-application-state

  1. Data
  2. Communication
  3. Control
  4. Session
  5. Location

Related Repos

https://github.com/hchiam/learning-reactjs

https://github.com/hchiam/chat-app-fcc-react-redux