http://christianhall.me/redux-101/
Christian Hall
Lead Developer @ Good
Do I need Redux to write good React apps?
Should I switch from (insert framework) to React + Redux right now?
Will my app/startup/life fail if I'm not using Redux?
Use what works for you. If you like some of the ideas behind Redux, use it or find a way to use the ideas with your stack.
Single source of truth
State is read only
Changes are made with pure functions
Plain JavaScript Objects
Only source of information for the store (via dispatch)
Must have a type
Action creators are just functions that return actions
{
type: ADD_TODO,
text: 'Build my first Redux app'
}
Specifiy how app's state changes in response to an action
(previousState, action) => newState
Must be pure functions
Can be composed to manage different parts of state tree
function todoApp(state = initialState, action) {
switch (action.type) {
case ADD_TODO:
return Object.assign({}, state, {
todos: [
...state.todos,
{
text: action.text,
completed: false
}
]
})
default:
return state
}
}
Holds application state
Allows access to state via getState()
Allows state to be updated via dispatch(action)
Handles low level listeners
Requires react-redux
for bindings
Component hierarchy should match state tree design
Container and presentational components
fin