Last active
August 1, 2016 17:20
-
-
Save andretw/2643f41f37a47d49306ba9ab65bc7326 to your computer and use it in GitHub Desktop.
reactjs-redux-change-state-in-action-creator-or-reducer-another
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 * as ACTION_TYPES from '../constants/action-types' | |
const action = (type, payload = {}) => ({ type, payload }) | |
const getUsernameSuccess = username => | |
action( | |
ACTION_TYPES.GET_USERNAME_SUCCESS, { | |
username, | |
message: 'Anything you want to show here.', | |
} | |
) | |
export { | |
getUsernameSuccess, | |
} |
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 * as ACTIONS from '../constants/action-types' | |
export default function (state = {}, action) { | |
const { type, payload } = action | |
switch (type) { | |
case ACTIONS.GET_USERNAME_SUCCESS: | |
return { | |
...state, | |
...payload, | |
} | |
... | |
default: | |
return state | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment