/
/
AddTodo form — controlled input with submit-on-enter and button click
8 export function AddTodo({ onAdd }: AddTodoProps) { 9 const [text, setText] = useState(""); 10
Form submission — prevents default, trims whitespace, calls the parent's addTodo, and resets the input. The guard clause prevents adding empty todos.
16 function handleSubmit(e: React.FormEvent) { 17 e.preventDefault(); 18 const trimmed = text.trim(); 19 if (!trimmed) return; 20 onAdd(trimmed); 21 setText(""); 22 }