Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

77
Visualizações
React : Animation timing through states and setTimeout

I try to handle game's computer side inputs through an array. Each element in the array will be set as the state 'currentTarget' to trigger the animation in child components. I think that my approach is probably wrong, anyway I wonder if there is a mean to use the setTimeout on each element of my IAInputsQueue state.

This is my non-working code :

Parent logic :

useEffect(()=>{
        if(!isPlayerTurn){
            
            IAInputsQueue.forEach((element, index) => {
                    window.setTimeout(() =>{
                    setCurrentTarget && setCurrentTarget(element) //Typescript checking
                },index *1000)
            });

            return () => IAInputsQueue.forEach(clearTimeout)
        }
    },[isPlayerTurn, IAInputsQueue, setCurrentTarget])

Child logic:

useEffect(() => {
        if(currentTarget === uid){
            animeButton()
            musicPlay()
        }
    },[currentTarget, uid, musicPlay, animeButton])
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda