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

330
Vistas
In react re-rendering, how to prevent resetting of the scrollbar to topmost point of other non-changed components?

I have the following sample react code

const A = () => {
    const [value1, setValue1] = React.useState(true);
    const [value2, setValue2] = React.useState(true);

    return (
    <div>
        <div class="first-comp">
             <FirstComponent data1={value1} data2={value2} />
        </div>
        <div class="second-comp">
             <SecondComponent onChange={() => {setValue1(false); setValue2(false);}} />
        </div>
    </div>
    )
}

When the SecondComponent is calling onChange, then both "first-comp" and "second-comp" are being re-rendered on the screen.

Since on re-rendering of SecondComponent, my scroll is resetting (i.e. If I had scrolled the internal scrollbar down in SecondComponent, on rerendering the SecondComponent renders at the top and not at the point where I had last scrolled to)

Is there a way that, when onChange changes the stateVariables, the <SecondComponent /> does not get re-rendered or the scroll does not get disturbed in SecondComponent or somehow the scroll gets preserved?

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

0

The issue was that on changing the state using setValue, react was running the UI of the second component.

Using shouldComponentUpdate() as mentioned here https://www.geeksforgeeks.org/reactjs-shouldcomponentupdate-method/ or use React.memo to prevent this re-rendering

I configured to not update when the value1 & value2 changes

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