Created
October 22, 2018 13:32
-
-
Save baso53/a552881b5c6a4629c5b0970ea32a54a5 to your computer and use it in GitHub Desktop.
implementing-sagas-reducer-1.js
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 { combineReducers } from "redux"; | |
const actionTypes = { | |
"FETCH_DATA_REQUEST": "FETCH_DATA_REQUEST", | |
"FETCH_DATA_SUCCESS": "FETCH_DATA_SUCCESS", | |
"FETCH_DATA_FAILED": "FETCH_DATA_FAILED" | |
}; | |
const initialState = { | |
name: '', | |
surname: '', | |
region: '', | |
error: '' | |
}; | |
const personState = (state = initialState, action) => { | |
switch(action.type) { | |
case actionTypes.FETCH_DATA_REQUEST: | |
return state; | |
case actionTypes.FETCH_DATA_SUCCESS: | |
return { | |
name: action.payload.name, | |
surname: action.payload.surname, | |
region: action.payload.region, | |
error: '' | |
}; | |
case actionTypes.FETCH_DATA_FAILED: | |
return { | |
...state, | |
error: action.payload | |
}; | |
default: | |
return state; | |
} | |
} | |
export default combineReducers({ | |
personState | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment