redux-hello
Start With Something Simple
Build a single-page example that increments and decrements a counter
Has all of the key elements of a real React/Redux application
Load libraries from the web to keep things simple
Page Outline
Using Babel to translate JSX and ES6 into whatever the browser needs
State
Doesn't get much simpler than that
Actions
Symbolic names instead of raw strings
Reducer
State will be initialized on the first call by default value of
state
Return a new state depending on the action type
If no action provided,
action.type
isundefined
Connect to Redux
combineReducers
lets us build reducers separately for different parts of the applicationOur application's actual state is an object with
counter
as its only key
createStore
then creates a store that passes actions through reducers
Handling Changes
The store is an observable
Every time state changes, it calls our (anonymous) callback...
...which does a React render
Display the entire state using
JSON.stringify
with 2-level indentationButtons that dispatch actions
store.dispatch
means "handle this action"Actions themselves are created by our utility functions
Start Things Off
A pre-defined action that triggers the initial rendering
Patterns
Some of these steps are the same for every Redux application
We will introduce tools that automate them
Last updated
Was this helpful?