Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created June 23, 2019 22:26
Show Gist options
  • Save jsmanifest/dcffa322989750b68e0d342c3ba38a7a to your computer and use it in GitHub Desktop.
Save jsmanifest/dcffa322989750b68e0d342c3ba38a7a to your computer and use it in GitHub Desktop.
const reducer = (state, action) => {
switch (action.type) {
case 'add-friend':
return {
...state,
friends: [...state.friends, action.friend],
history: [...state.history, state],
}
case 'undo': {
const isEmpty = !state.history.length
if (isEmpty) return state
return { ...state.history[state.history.length - 1] }
}
default:
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment