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

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