diff --git a/client/components/molecules/AddTodo/AddTodo.js b/client/components/molecules/AddTodo/AddTodo.js index 29203a6..0eb0f78 100644 --- a/client/components/molecules/AddTodo/AddTodo.js +++ b/client/components/molecules/AddTodo/AddTodo.js @@ -1,8 +1,24 @@ -import React from 'react'; +import React, { useState } from 'react'; import PropTypes from 'prop-types'; import Button from '_atoms/Button'; -export default function AddTodo({ text, updateText, addTodo }) { +import useKeypress from '_hooks/useKeypress'; + +export default function AddTodo({ addTodo }) { + const [text, setText] = useState(''); + + const onAddTodo = () => { + if (text) { + addTodo(text); + setText(''); + } + }; + + useKeypress('Enter', onAddTodo); + + const updateText = e => setText(e.target.value); + + return (
@@ -11,7 +27,7 @@ export default function AddTodo({ text, updateText, addTodo }) {