Created
March 25, 2019 17:52
-
-
Save brookback/200a0b04ef17c7e69e365e4739812a3f 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
import React from 'react'; | |
interface Props { | |
onAddTodo: (newDescription: string) => void; | |
} | |
export const MyForm = (props: Props) => { | |
const handleSubmit = (evt) => { | |
evt.preventDefault(); | |
// reset description state | |
props.onAddTodo(evt.target.value); | |
}; | |
return (<form onSubmit={handleSubmit}> | |
<input type="text" /> | |
<input type="submit" /> | |
</form>); | |
}; | |
// Usage: | |
<MyForm onAddTodo={ | |
(newDescription) => { | |
// add newDescription as new todo | |
} | |
} /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment