File size: 952 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 28 29 30 31 32 33 34 35 36 37 38 | import React, { useState } from 'react';
function ItemForm({ onAdd }) {
const [name, setName] = useState('');
const [description, setDescription] = useState('');
const handleSubmit = async (e) => {
e.preventDefault();
if (!name.trim()) return;
await onAdd({ name: name.trim(), description: description.trim() });
setName('');
setDescription('');
};
return (
<form onSubmit={handleSubmit} style={{ marginBottom: '1rem' }}>
<input
type="text"
placeholder="Name"
value={name}
onChange={(e) => setName(e.target.value)}
required
style={{ marginRight: '0.5rem' }}
/>
<input
type="text"
placeholder="Description"
value={description}
onChange={(e) => setDescription(e.target.value)}
style={{ marginRight: '0.5rem' }}
/>
<button type="submit">Add Item</button>
</form>
);
}
export default ItemForm;
|