Created
March 9, 2019 05:36
-
-
Save asleepysamurai/b7d869fd5148ab387613fcd4661ab0b3 to your computer and use it in GitHub Desktop.
TodoInput useState
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
/** | |
* TodoInput Component | |
*/ | |
import React, { useState } from 'react'; | |
function TodoInput({ | |
onAdd | |
}) { | |
const [text, setText] = useState(''); | |
const onTextChange = (ev) => setText(ev.currentTarget.value); | |
const addTodoItem = () => { | |
onAdd(text); | |
setText(''); | |
}; | |
return ( | |
<div | |
className="todo-input"> | |
<input | |
type="text" | |
onChange={onTextChange} | |
value={text} | |
placeholder="Enter Todo Here" /> | |
<button | |
onClick={addTodoItem}> | |
Add Todo | |
</button> | |
</div> | |
); | |
}; | |
export default TodoInput; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment