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

177
Vistas
In React with Socket.io: Calling function inside useEffect don't give me the actual variable

When i call my function getNextCard() directly with <button onClick={getNextCard}>NextCardRound</button></div> it works, gives me the right result everytime. But when i try to call it from socket.on('end-turn') it don't give me the updated round value (that comes from socket.on('get-next-card')). How can i get the updated value from round? Thank you

useEffect(() => {
    console.log('useEffect: ' + socket);
  //ALL EVENTS = ROOM EVENTS
  //LISTENERS FOR COMMON EVENTS LIKE TABLE CARDS:
  socket.on('get-next-card', (tablecards, tblcards, nextround) => {
    console.log('get-next-card: ', tablecards, tblcards, nextround);
    console.log("ESSE É O ROUND Q CHEGA DO BACK PARA ATUALIZAR: ", nextround);
    if(nextround!=='showdown'){
    //let newArray = tablecards.concat(tblcards);
    setRound(nextround);
    setTableCards([...tablecards, ...tblcards]);
    }
    })

    socket.on('end-turn', () => {
      console.log('end-turn: ', round);
      
        getNextCard();
    
    })
    }) ```
    ```
function getNextCard(){
    console.log("ESSE É O ROUND ANTES E Q VAI SER ENVIADO P BACK: "+round);
    socket.emit('next-card', tablecards ,round, room, (cb)=>{
      console.log("get next card function ", cb);
    })
  }
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