Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created June 23, 2019 22:30
Show Gist options
  • Save jsmanifest/1bbbe14c93b9df4ab8810831b65fa583 to your computer and use it in GitHub Desktop.
Save jsmanifest/1bbbe14c93b9df4ab8810831b65fa583 to your computer and use it in GitHub Desktop.
const useApp = () => {
const [state, dispatch] = useReducer(reducer, initialState)
const onSubmit = (friend, resetValues) => (e) => {
e.preventDefault()
if (!friend.name) return
dispatch({ type: 'add-friend', friend })
resetValues()
}
const undo = () => {
dispatch({ type: 'undo' })
}
return {
...state,
onSubmit,
undo,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment