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

155
Vistas
Closure with callback

Ok, here's a closure issue (i think) that I'm dealing with. Can't wrap my head around it. I have a component and I'm trying to get the updated value of shouldDropAbove into my callback onStepItemDrop:

export const StepItem = () => {
  const [shouldDropAbove, setShouldDropAbove] = React.useState<boolean>()

  React.useEffect(() => {
    console.log(shouldDropAbove) //outputs updated value correctly
  }, [shouldDropAbove])

  console.log(shouldDropAbove) //also is outputting the updated value correctly

  const onStepItemDrop = (draggingStep) => {
    console.log(shouldDropAbove) //outputting undefined ?????
  }

  return (
    <Droppable
      onDrop={onStepItemDrop}
      setShouldDropAbove={setShouldDropAbove} //Droppable updates setShouldDropAbove correctly
    >
      {jsx stuff}
    </Droppable>
  )
}
export const Droppable = ({onDrop, setShouldDropAbove}) => {
  //updating setShouldDropAbove
}

What is going on here and why can't I get the correct value in the callback?

about 4 years ago · Santiago Gelvez
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