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

320
Vistas
How to detect page refresh on react

I've been stuck on this for hours, how can I detect a page refresh and reroute the user to a specific path? /error for example

I'm using useNavigate for rerouting, it works but I dont know how to properly listen for a page refresh

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

here is what you need in this example. In fact, with this method you can detect if that page has refreshed or reloaded, so you can use the useEffect and performance.

You use the method navigate to be able to navigate the pages. Don't forget if you have any state you can include it in the dependency array of the useEffect().

import React, { useEffect } from "react";

export default function NavigationDectector() {
  const { navigate} = useNavigate();
  useEffect(() => {
    if (performance.navigation.type === 1) {
      console.log("This page is reloaded");
      // here you can navigate 
    } else {
      console.log("This page is not reloaded");
    }
    // if you have any state which you depend on the reload put it in the 
    array of the use effect
  },[]);

  return <div></div>;
}

I hope this can helps you

about 4 years ago · Santiago Gelvez 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