Skip to content

Instantly share code, notes, and snippets.

@baso53
Created October 22, 2018 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baso53/a552881b5c6a4629c5b0970ea32a54a5 to your computer and use it in GitHub Desktop.
Save baso53/a552881b5c6a4629c5b0970ea32a54a5 to your computer and use it in GitHub Desktop.
implementing-sagas-reducer-1.js
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