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

145
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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