Skip to content

Instantly share code, notes, and snippets.

@radiegtya
Created May 13, 2018 03:21
Show Gist options
  • Save radiegtya/cad5031351d006aafffd1e4486ab8156 to your computer and use it in GitHub Desktop.
Save radiegtya/cad5031351d006aafffd1e4486ab8156 to your computer and use it in GitHub Desktop.
// #1. make the default state, data is an object to save profile data, and isLoading is boolean to know whether data is ready or not
const initialState = {
isLoading: false,
data: {}
}
// #2. a function to decide what state should be returned by each action.type
const profilesReducer = (state = initialState, action) => {
switch (action.type) {
case 'GET_PROFILE_PENDING':
return {...state, isLoading: true}
case 'GET_PROFILE_FULFILLED':
return {...state, data: action.payload.data, isLoading: false}
default:
return state
}
}
export default profilesReducer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment