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

474
Vistas
React hooks window.scrollTo(0, 0) not working when overflow auto

I am using React at the moment, when I click on a button that takes me to another page, by default it goes to the bottom of my page. Tried using window.scrollTo(0, 0); but it doesn't seem to work.

const handleRedirection = () => {
    history.push(/home);
    window.scrollTo(0, 0);
  };

The page I would like to go to currently has css set as

height: calc(100vh - 50px);
overflow: scroll;

Was wondering is there a solution to fix this issue. Thanks! 🙏

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

0

you can scroll to top based on route change

try this:

import { useLocation } from "react-router-dom";

//your codes code

  const { pathname } = useLocation();

  useEffect(() => {
    window.scrollTo(0, 0);
  }, [pathname]);

//your codes

also, you can use it as a top-level component to apply this to all your pages

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