todo
31 строка · 820.0 Байт
1import React, { useState } from 'react';
2import './TodoForm.css'
3
4interface ToDoFormProps {
5setTasks: React.Dispatch<React.SetStateAction<Task[]>>;
6}
7
8const ToDoForm: React.FC<ToDoFormProps> = ({ setTasks }) => {
9const [input, setInput] = useState<string>('');
10
11const handleSubmit = (e: React.FormEvent) => {
12e.preventDefault();
13if (input.trim()) {
14setTasks(prev => [...prev, { id: Date.now(), text: input, completed: false }]);
15setInput('');
16}
17};
18
19return (
20<form onSubmit={handleSubmit}>
21<input
22type="text"
23value={input}
24onChange={(e) => setInput(e.target.value)}
25placeholder="What needs to be done?"
26/>
27</form>
28);
29}
30
31export default ToDoForm;
32