Last active
April 15, 2019 20:07
-
-
Save benkissi/88c4504873c81fc0738d14968fa5b9fb to your computer and use it in GitHub Desktop.
Context blog
This file contains 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 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