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

139
Views
React hook inside promise not even triggered! not log anything?

why this code doesnt work? i create this custom hook to call hook useState:

 export const useAnimer=({})=>{
    const [animList, setAnimList] = useState({})
    useEffect(()=>{

    .......

    onDone:(anim,name)=>{
      console.log("anim list updating...")
      
      setAnimList((a)=>{
      console.log("anim list updated",a)

      return a
    })}

    ........
    },[depedency])}

it's only print

console.log("anim list updating")

but never print

console.log("anim list updated")

here where onDone is used in anotherfile.js. it's called every 100ms inside asnyc function that returned promise object

  const animIt = async (frame)=>{
      while(true){
        frame.pools.timepassed+=100
          frame.pools.frames.forEach((a,i)=>{ 
              a.onDone(a)           
          })
           await new Promise(resolve=>
            setTimeout(()=>{
              resolve()
            },100))
        
        }
       }
        
      }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

first, you cannot use hooks in this way a[name]=anim you can add new values to object like this {...a,[name]:anim} and then add it to your state : setAnimList({...a,[name]:anim})

second, if I were you I would define Arrow function and return it, something like this:

export const useAnimer=({})=> {
const [animList, setAnimList] = useState({})

const handleAddAnim = (anim, name) => {
    setAnimList({...animList, [name]: anim})
}

return {
    animList,
    handleAddAnim
}

}

and whenever I want to use it i would call it in this way :

const {animList, handleAddAnim} = useAnimer();

hope I'm helpful

about 4 years ago · Juan Pablo Isaza Report
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!