Ok, aquí hay un problema de cierre (creo) con el que estoy lidiando. No puedo envolver mi cabeza alrededor de eso. Tengo un componente y estoy tratando de obtener el valor actualizado de shouldDropAbove
en mi devolución de llamada 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 }
¿Qué está pasando aquí y por qué no puedo obtener el valor correcto en la devolución de llamada?