const [comment, setComment] = useState('')
const [commentList, setCommentList] = useState([])
const handlerComment = () => {
setCommentList(PrevList =>[...prevList, comment]);
setComment('');
}
const handleKeyDown = e => {
if (e.key === 'Enter') {
handlerComment();
}
};
...
<input onChange={e => setComment(e.target.value)}
onKeyDown={handleKeyDown} placeholder="댓글을 입력해주세요"
value={comment} />
<button onClick={handlerComment}>등록</button>
...
{commentList.map((commentItem, index) => (
<div key={index} title="user">
<div>
<div>조수진</div>
<div title="small">찬성</div>
<div title="time">3분전</div>
</div>
<div>{commentItem}</div>
</div>
))}