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

388
Visualizações
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
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