File size: 561 Bytes
cce8120 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import React, { useState } from 'react';
function TodoForm({ onAdd }) {
const [title, setTitle] = useState('');
const handleSubmit = (e) => {
e.preventDefault();
if (!title.trim()) return;
onAdd(title.trim());
setTitle('');
};
return (
<form onSubmit={handleSubmit} style={{ marginBottom: '1rem' }}>
<input
type="text"
placeholder="New todo"
value={title}
onChange={e => setTitle(e.target.value)}
/>
<button type="submit">Add</button>
</form>
);
}
export default TodoForm;
|