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

74
Views
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
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!