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

121
Vistas
Wait for user click then continue execution in React

I am making React Card game with hooks and all that. But I can't figure out how to implement wait for user click when certain condition is met (when is turn on human player for example). I need it to work on certaint buttons (cards), not global window click. I tried with async await and event listeners but can't get it to work (event listener not reconized, not sure if it works in React). If someone could help me out with template on how to do that. Thank you for the help in advance. Code sample is below

export function playTurn(...players) {
  let cardsThrown = 0;

// for example if lastWinner or secondPLayer===human wait for on click on "classname"

  whoPlaysFirst(...players);

  let lastWinner = lastTurnWinner(...players);

  const { hand: lastTurnWinnerHand } = lastWinner;

  lastWinner.currentCard = lastWinner
    .playCard(sample(lastTurnWinnerHand))
    .shift();
  Game.winningSuit = lastWinner.currentCard.suit;
  cardsThrown += 1;
  console.log(lastWinner.currentCard);

  while (cardsThrown !== 4) {
    let secondPlayer = nextPlayer(Game.lastPlayer);
    secondPlayer.currentCard = secondPlayer
      .playCard(sample(secondPlayer.hand))
      .shift();
    cardsThrown += 1;
    console.log(secondPlayer.currentCard);

    lastWinner = winningCard(lastWinner, secondPlayer); //Pobjednik ostaje
    Game.lastPlayer = secondPlayer;
  }
  console.log("Pobjednicka karta je: ", lastWinner.currentCard);

  nextTurn(lastWinner, ...players);
}
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