Created
June 23, 2019 22:30
-
-
Save jsmanifest/1bbbe14c93b9df4ab8810831b65fa583 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 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