Reading Notes
Why choose Redux instead of the Context API for global state? The jury seems to be out on this question, many examples online point to either one as being the better choice or in some cases they should be used together. Context appears to be the better option when dealing the static data like theme selection while Redux is often better for storing global state data that is more dynamic.
What is the purpose of a reducer? A function that determines the changes to an applications state, uses the action to determine the change
What does an action contain? Actions are the only way to updated data in the store. Must include a type and can pass a payload containing data
Why do we need to copy the state in a reducer? Data in the store is immutable, so to make changes a copy must be made in the reducer so that it can be changed
store.dispatch()
and pass in an action objectimport {combineReducers, createStore } from 'redux';
const userReducer = (state={}, action) => { return state };
const reducers = combineReducers({user: userReducer, tweets: tweetReducer})
createStore
function takes preloadedState
as a second argumentcombineReducers
must satisfy the following:
state
given to it is undefined, must return initial state for the specific reducer