/
githubmirror
/
reactjs-interview-questions
Обзор
Документация
Войти
/
githubmirror
/
reactjs-interview-questions
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
coding-projects/todo-app/src/components/TodoForm.tsx
27 строк
769 B
sudheerj
Added todo-app project
10 авг 2026, 12:25
10 авг 2026, 12:25
6dc37e9
Код
Авторство
О чём код?
import {useState} from "react"; type TodoFormProps = { onAdd: (label: string) => void } export function TodoForm({onAdd}: TodoFormProps) { const [newTodo, setNewTodo] = useState(""); const handleSubmit = () => { const label = newTodo.trim(); if(!label) { return; } onAdd(label); setNewTodo(""); } return ( <div className="todo-form"> <input type="text" placeholder="Add your todo" value={newTodo} onChange={(e: React.ChangeEvent<HTMLInputElement>) => setNewTodo(e.target.value)}></input> <button type="submit" onClick={handleSubmit} onKeyDown={(e) => {if(e.key === 'Enter') {handleSubmit()}}}> Submit </button> </div> ) }