Created
March 9, 2019 05:38
-
-
Save asleepysamurai/e94b7adc02218cc135a5c4e83c8cb4e3 to your computer and use it in GitHub Desktop.
TodoInput Function Component
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, useCallback } from 'react'; | |
function TodoInput({ | |
onAdd | |
}) { | |
const [text, setText] = useState(''); | |
const onTextChange = useCallback((ev) => setText(ev.currentTarget.value), [setText]); | |
const addTodoItem = useCallback(() => { | |
onAdd(text); | |
setText(''); | |
}, [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