Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda