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

120
Vistas
Add dynamic event listners in React

Is there any way where I can add dynamic eventlistners, which will be triggered for specific urls and it can detect which events are called on that specific url?

For ex - My react apps have multiple routes and out of those routes for specefic routes I want to see which actions (by actions I mean button click, keypress etc) are executing and based on that I want to call an API with the action that is being called.

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

0

Yes – add an event listener in an useEffect (and clean it in the effect cleanup function) in that route's component:

function MyView() {
  React.useEffect(() => {
    const handler = e => console.log(e);
    window.addEventListener('click', handler);
    return () => window.removeEventListener('click', handler);
  }, []);
  return <>Hello!</>;
}

// Not shown: hooking MyView up to your router.

You can also use a premade event hook such as react-use's 'useEvent'.

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