import { useState } from 'react'; import PropTypes from 'prop-types'; import Button from 'react-bootstrap/Button'; import Form from 'react-bootstrap/Form'; import InputGroup from 'react-bootstrap/InputGroup'; export function AddItemForm({ onNewItem }) { const [newItem, setNewItem] = useState(''); const [submitting, setSubmitting] = useState(false); const submitNewItem = (e) => { e.preventDefault(); setSubmitting(true); const options = { method: 'POST', body: JSON.stringify({ name: newItem }), headers: { 'Content-Type': 'application/json' }, }; fetch('/api/items', options) .then((r) => r.json()) .then((item) => { onNewItem(item); setSubmitting(false); setNewItem(''); }); }; return (
setNewItem(e.target.value)} type="text" placeholder="New Item" aria-label="New item" />
); } AddItemForm.propTypes = { onNewItem: PropTypes.func, };