Skip to content

Instantly share code, notes, and snippets.

@crobinson42
Created January 8, 2018 21:42
Show Gist options
  • Save crobinson42/330d20f00435190379bf0264b6270f6b to your computer and use it in GitHub Desktop.
Save crobinson42/330d20f00435190379bf0264b6270f6b to your computer and use it in GitHub Desktop.
// containers/user/actions.js
export const getUser = () => ({
type: 'GET_USER',
payload: {
request: {
url: '/people',
},
},
})
// containers/user/reducer.js
const defaultState = {
loading: false,
}
export default function (state = defaultState, action) {
switch (action.type) {
case 'GET_USER_LOAD':
console.log('user reducer: http req loading...')
return {
...state,
loading: true,
}
case 'GET_USER_SUCCESS':
console.log('user reducer: http req success...', action.payload)
return {
...state,
...action.payload.data,
}
case 'GET_USER_FAIL':
console.log('user reducer: http req failed...', action.payload)
return {
...defaultState,
}
default:
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment