Created
May 13, 2018 03:21
-
-
Save radiegtya/cad5031351d006aafffd1e4486ab8156 to your computer and use it in GitHub Desktop.
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
// #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