Skip to content

Instantly share code, notes, and snippets.

@asleepysamurai
Created March 9, 2019 05:38
Show Gist options
  • Save asleepysamurai/e94b7adc02218cc135a5c4e83c8cb4e3 to your computer and use it in GitHub Desktop.
Save asleepysamurai/e94b7adc02218cc135a5c4e83c8cb4e3 to your computer and use it in GitHub Desktop.
TodoInput Function Component
/**
* 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