Skip to content

Instantly share code, notes, and snippets.

@madan712
Created June 1, 2019 10:34
Show Gist options
  • Save madan712/839dfba5ce5efca9115cfef6a5ad73a4 to your computer and use it in GitHub Desktop.
Save madan712/839dfba5ce5efca9115cfef6a5ad73a4 to your computer and use it in GitHub Desktop.
AppReducer.js - Example with React, Redux and Axios API
const initialState = {
name: '',
response: ''
};
export default function AppReducer(state = initialState, action) {
const newState = Object.assign({}, state);
switch (action.type) {
case 'UPDATE_NAME':
newState.name = action.name;
return newState;
case 'LOAD_RESPONSE':
newState.response = action.response;
return newState;
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment