Skip to content

Instantly share code, notes, and snippets.

@natekandler
Created March 20, 2019 21:54
Show Gist options
  • Save natekandler/25d701ae37545a49ab571c645faa1217 to your computer and use it in GitHub Desktop.
Save natekandler/25d701ae37545a49ab571c645faa1217 to your computer and use it in GitHub Desktop.
redux example
// In the homePageModule
// homePage/actionTypes.js
export const HOMEPAGE_ACTION = 'homePage/HOMEPAGE_ACTION';
// homePage/actions.js
export const homePageAction = (data) => {
return {
type: actionTypes.HOMEPAGE_ACTION,
payload: data
};
}
// homePage/reducers.js
export default function(state = defaultState, action = {}) => {
switch (action.type) {
case actionTypes.HOMEPAGE_ACTION:
return {
...state,
...payload.data
};
}
}
// top level rootReducer.js
import homeReducer from './homePage/reducer';
const rootReducer = combineReducers({
homeReducer,
(any other reducers)
});
export default rootReducer;
// store.js
import rootReducer from './rootReducer';
...
const store = createStore(rootReducer, initialState)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment