Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save justin3737/b26c2008db09b0d40ed78651244cfcd0 to your computer and use it in GitHub Desktop.
Save justin3737/b26c2008db09b0d40ed78651244cfcd0 to your computer and use it in GitHub Desktop.
function reducer(state = [], action) {
switch (action.type) {
case 'ADD_ATTENDEE':
// Return a new array with old state and added attendee.
return [{
name: action.name,
color: action.color
},
...state
];
case 'REMOVE_ATTENDEE':
return [
// Grab state from begging to index of one to delete
...state.slice(0, action.index),
// Grab state from the one after one we want to delete
...state.slice(action.index + 1)
];
default:
return state;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment