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

125
Views
React component not scrolling to top on re render

I have a React class component which is separated into left half and right half, left side has options to select like from Fruits, Vegetables, Junk and on right side, a list of that item is shown. Issue: Suppose I click on Fruits and scroll the right side to mid of list, then again clicking on Fruits take me to the place where I previously was. Expected: Clicking on Fruit again should show the list from top.

I tried window.scrollTo(0,0) and window.scrollBy(0, topRef.current.offsetTop) but it is scrolling the entire window including left side. How can I just scroll the right side of items on re-render?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Try using ScrollIntoView instead of scrollTo and scrollBy.

add an Id to the element where you intend to scroll and use scrollIntoView with that id

document.getElementById(elId).scrollIntoView({behavior: "smooth", block: "nearest", inline: "nearest"});

about 4 years ago · Santiago Trujillo Report
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!