Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

89
Vistas
ReactJS - Get two divs two follow each others scrolling

I have two divs one is master and the other one is slave, I would like slave and master to follow each others scrolling.

master will always have the same width and height but slave can have any width and any height.

Problem: when I start scrolling it triggers an infinite loop because I'm using two useEffects to look at each others scroll percentage and update scrolling accordingly.

Sandbox: https://codesandbox.io/s/xenodochial-feather-3teev?file=/src/App.js

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I figured it out, using useEffect hooks was a mistake, because when one position changes the other will as well and this caused an infinite loop. I simply used the onScroll prop and selected the parent node and then the other div within the parent and modified the scroll position that way.

Easiest way to understand is to look at the code: https://codesandbox.io/s/react-js-scroll-sync-ee9wb

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda