Skip to content

Instantly share code, notes, and snippets.

@andretw
Last active August 1, 2016 17:20
Show Gist options
  • Save andretw/2643f41f37a47d49306ba9ab65bc7326 to your computer and use it in GitHub Desktop.
Save andretw/2643f41f37a47d49306ba9ab65bc7326 to your computer and use it in GitHub Desktop.
reactjs-redux-change-state-in-action-creator-or-reducer-another
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,
}
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