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

144
Vistas
How can I use variables inside window before unload

I am trying to use variables defined inside my React function in the window.addEventListner('beforeunload') function however it seems that the variables are already gone at that point. I need to do this to logout the user by calling a function inside my middleware called leaveRoom and pass in the variables "code" and "name". This is what I have tried:

...
149 window.addEventListener("beforeunload", e => 
150 {
151   if(!joined) return;
152   e.preventDefault();
153   leaveRoom({ code: code, username: name });
154 });
...
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It is not the best way but you can define globals.

window.code = "code"
window.username = "Cem"

after that, you can access these variables from anywhere.

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