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);
})
}