Skip to content

Instantly share code, notes, and snippets.

@benkissi
Last active April 15, 2019 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benkissi/88c4504873c81fc0738d14968fa5b9fb to your computer and use it in GitHub Desktop.
Save benkissi/88c4504873c81fc0738d14968fa5b9fb to your computer and use it in GitHub Desktop.
Context blog
const TodoInput = props => {
let todo;
return (
<AppConsumer>
{({ addTodo }) => (
<form
onSubmit={e => {
e.preventDefault();
}}
>
<Input
type="text"
id="todoInput"
onChange={e => {
todo = e.target.value;
}}
placeholder="type todo here"
/>
<Button
type="submit"
onClick={() => {
if (todo) {
addTodo(todo);
const inputEl = document.getElementById("todoInput");
inputEl.value = "";
}
}}
>
Add Todo
</Button>
</form>
)}
</AppConsumer>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment