Skip to content

Instantly share code, notes, and snippets.

@saigowthamr
Created July 7, 2018 12:37
Show Gist options
  • Save saigowthamr/52f707d08c06a744cbf3df93e9b4c67e to your computer and use it in GitHub Desktop.
Save saigowthamr/52f707d08c06a744cbf3df93e9b4c67e to your computer and use it in GitHub Desktop.
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