import React, { useState } from 'react'; type Props = { addRoom: (name: string) => Promise; } const NewRoomForm: React.FC = (props) => { const [name, setName] = useState(''); const [processing, setProcessing] = useState(false); const [error, setError] = useState(''); function addRoom(ev: React.FormEvent) { ev.preventDefault(); setProcessing(true); setError(''); props.addRoom(name).then(() => { setName(''); }).catch(err => { setError(err.toString()); }).then(() => { setProcessing(false); }); } return (
{ setName(event.target.value); }} /> {error &&

{error}

}
); }; export default NewRoomForm;