In the parent div, there is a div and a textarea. I am attempting to synchronize the scrollTop value of the textarea with the div so that they move together when scrolling.
The issue arises when I input text into the textarea and hit enter for a new line. The div's scrollTop value does not update, while the textarea's does.
Upon hitting enter again, both values update, but it appears that the div's scrollTop value lags one step behind the textarea.
https://codesandbox.io/s/objective-feather-ngq8t
handleScroll = (e) => {
setTextareaScrollTop(e.target.scrollTop);
e.target.previousElementSibling.scrollTop = e.target.scrollTop;
setDivScrollTop(e.target.previousElementSibling.scrollTop);
};