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

268
Vistas
In react how to call a function on reaching a specific URL in the browser?

I'm using window.location.href to fetch url from the browser. As soon as the specified "url" is reached, it should call the fuction abc(), somewhat like below:

if (window.location.href === "url") {
  abc(); //calls the function abc
}

function abc () {
  //code..
}

How do I do it the right way?

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

0

you can use this

useEffect(() => {
 if(window.location.href === 'url'){
  abc()
 }
},[window.location.href])
about 4 years ago · Juan Pablo Isaza Denunciar

0

I would make some hook that does that for you. Example:

const useAbcHook = () => {
  const location = useLocation()

  useEffect(() => {
   if(location.pathname === "mychoiceurl"){
    abc()
    }
  },
  [url]
}

Then to use the hook

const MyComp = () => {
  useAbcHook()
  return(<div>....</div>)
}
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