Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

385
Views
ReactJS: element.ScrollLeft does not change value after resizing window

I have a state called scrollStatus, where I track the current scroll position of a div, and I set its value using a ref and element.scrollLeft when scrolling:

const scrollHandle = () => {
setScrollStatus(container.current?.scrollLeft);
console.log(scrollStatus);
}

So when doing console.log I get a different value of scrollStatus, which is what I want:

enter image description here

When I resize the window by a large margin (let's say from desktop to mobile view), the scroll value will change drastically, which I expected for it to happen since my container's width is percentage based.

Here in the console, you can see the value changed to 375 after I resize the window to mobile view:

enter image description here

However, when I try to scroll again after resizing the window, the value of scrollStatus doesn't change. It retains the current position value after I resize the window:

enter image description here

(The value still won't change even if I resize the window again)

Any idea what's going on here and how to fix it?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!