Skip to content

Instantly share code, notes, and snippets.

@brookback
Created March 25, 2019 17:52
Show Gist options
  • Save brookback/200a0b04ef17c7e69e365e4739812a3f to your computer and use it in GitHub Desktop.
Save brookback/200a0b04ef17c7e69e365e4739812a3f to your computer and use it in GitHub Desktop.
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