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

130
Vistas
How put scroll to top when scroller is inside Div in React

As you can see in the image the scroller is in the middle. Now when goes to an organization I want the scroller to go up to its start position.

const scrollToRef = (ref) => window.scrollTo(0, ref.current.offsetTop);
const ListItemScroll = (props) => {
  let {
    resultList,
    indexChange,
    radioValue,
    radioHandleChange,
    setParamsInc,
    searchText,
    loading,
    noRecords
  } = props;
  const listInnerRef = useRef();

  const onScroll = () => {
    if (searchText.length === 0) {
      if (listInnerRef.current) {
        const { scrollTop, scrollHeight, clientHeight } = listInnerRef.current;
        if (scrollTop + clientHeight === scrollHeight) {
          setParamsInc((prev) => prev + 1);
        }
      }
    }
  };

This is what I am trying to do but it doesn't work

  const executeScroll = () => scrollToRef(listInnerRef);
  useEffect(() => {
    console.log("scroll");
    executeScroll();
  }, [indexChange]);

  return (
    <>
      <div
        onScroll={onScroll}
        ref={listInnerRef}
        style={{ overflow: "auto", overflowX: "hidden", height: "100%" }}
      >
        List of filter values
      </div>
    </>
  );
};
about 4 years ago · Juan Pablo Isaza
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