Created
March 20, 2019 21:54
-
-
Save natekandler/25d701ae37545a49ab571c645faa1217 to your computer and use it in GitHub Desktop.
redux example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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