I am building an app and users can add comments, I can't get the div to auto scroll to the bottom so when the user comments their latest comment doesn't show unless they scroll as I have overflow-y set to scroll. How could I implement this in React please?
Comments div
<div className = 'comments'>
{item.comments.map((comment,index) => {
return <h6 key = {index}><span className ='comment-name'> {comment.postedBy.name} </span> {comment.text}</h6>}
</div>
comments css
.comments {
max-height: 20vh;
overflow-y: scroll;
padding-left: 1rem;
}
Form submit code
<form onSubmit = {(e) => {
e.preventDefault()
makeComment(e.target[0].value, item._id)
e.target[0].value = null }
</form>