-
-
Save jks8787/657b1a8c7af73119a27b5f12e197d13b to your computer and use it in GitHub Desktop.
reducers for react+ redux -- Medium Article gist
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
import {combineReducers} from 'redux'; | |
import stuff from './stuffReducer'; | |
const rootReducer = combineReducers({ | |
stuff | |
}); | |
export default rootReducer; |
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
import initialState from './initialState'; | |
import {FETCH_STUFF, RECEIVE_STUFF} from '../actions/actionTypes'; | |
export default function stuff(state = initialState.stuff, action) { | |
let newState; | |
switch (action.type) { | |
case FETCH_STUFF: | |
console.log('FETCH_STUFF Action') | |
return action; | |
case RECEIVE_STUFF: | |
newState = action.stuff; | |
console.log('RECEIVE_STUFF Action') | |
return newState; | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment