Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
En React con Socket.io: la función de llamada dentro de useEffect no me da la variable real

Cuando llamo a mi función getNextCard() directamente con <button onClick={getNextCard}>NextCardRound</button></div> funciona, siempre me da el resultado correcto. Pero cuando trato de llamarlo desde socket.on('end-turn') no me da el valor redondo actualizado (que viene de socket.on('get-next-card')). ¿Cómo puedo obtener el valor actualizado de la ronda? Gracias

 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 EQ 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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!