Scroll down to bottom of a div

I am try to make it automaticly scroll down on every button button click
in ReactJs
what i have tried:

const chat = document.getElementById("ChatArea");
chat.scrollTop = chat.scrollHeight;

the div with the scroll bar:

.ChatArea{
border: 1px solid gray;
width: 50%;
margin: auto;
height: 400px;
display: flex;
  flex-direction: column;
  overflow-y: scroll;
}

i get the error:
Cannot read properties of null (reading ‘scrollHeight’)

This means that document.getElementById("ChatArea") is returning null instead of an element. Are you sure the id is correct?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.