Created
June 1, 2019 10:34
-
-
Save madan712/839dfba5ce5efca9115cfef6a5ad73a4 to your computer and use it in GitHub Desktop.
AppReducer.js - Example with React, Redux and Axios API
This file contains hidden or 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
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