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

217
Vistas
How do I create SyntheticEvent listener on the document?

In the website I'm currently developing, native events (regular KeyboardEvents) produce unwanted behaviour (using old versions of state and refs), whilst SyntheticEvents (which I believe are React.KeyboardEvents) work flawlessly. I'm trying to put a SyntheticEvent onKeyDown listener on the document (so that the keypress can be handled no matter where the focus is), is there any way to achieve this? To work around this, I've made a wrapper element across the whole app with a onKeyDown listener, this does not work well though, because it does not register all the presses (such as when a hamburger menu or a full screen photo is focused, which I think happens due to their absolute/fixed positioning).

Example of using document.addEventListener("keydown", handleKeyDown), which fires native element, but has incorrect behaviour (handleKeyDown uses outdated refs), but registers keypresses globally:

  • Stack Trace: Stack trace of addEventListener
  • Event Type: Event type addEventListener

Example of using app wrapper in which handleKeyDown works correctly (the refs are current), probably because it is a SyntheticEvent. It does not register clicks globally though:

  • Stack Trace: Stack trace of app wrapper
  • Event Type: Event type of app wrapper
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