Spaces:
Runtime error
Runtime error
import { useState } from 'react' | |
import PropTypes from 'prop-types' | |
function InputBar({ onSend }) { | |
const [text, setText] = useState('') | |
const handleSubmit = (e) => { | |
e.preventDefault() | |
if (!text.trim()) return | |
onSend(text) | |
setText('') | |
} | |
return ( | |
<form className="input-bar" onSubmit={handleSubmit}> | |
<input | |
type="text" | |
value={text} | |
onChange={(e) => setText(e.target.value)} | |
placeholder="Type a message..." | |
/> | |
<button type="submit">Send</button> | |
</form> | |
) | |
} | |
InputBar.propTypes = { | |
onSend: PropTypes.func.isRequired, | |
} | |
export default InputBar | |