Created
July 7, 2018 12:37
-
-
Save saigowthamr/52f707d08c06a744cbf3df93e9b4c67e to your computer and use it in GitHub Desktop.
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 initalState = { | |
num: 0, | |
todos: [], | |
data: "", | |
users:null | |
} | |
function reducer(action, state =initalState ) { | |
switch (action.type) { | |
case "INC": | |
return { | |
...state, | |
num: state.num + 1 | |
}; | |
case "DEC": | |
return { | |
...state, | |
num: state.num - 1 | |
}; | |
case "ADD_TODO": | |
return { | |
...state, | |
todos: [...state.todos, action.text] | |
}; | |
case "GET_DATA": | |
return { | |
...state, | |
data: action.data | |
}; | |
case 'GET_USERS': | |
return { | |
...state, | |
users:action.users | |
} | |
default: | |
return state; | |
} | |
} | |
export {reducer} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment