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

163
Views
React state not being changed after passed down from parent

I a setState function being passed down from a parent component, I want to setTheState of the parent setter if the enterKey is pressed. Though, when I set the state nothing happens and I'm still left with an empty array

Here's the code snippet

const { check, setCheck } = props // receive from props
const callApi = async (onEnter) => {
  const res = await callFunction('', data)
  if (res) {
    setResults(res)
    if (onEnter) {
      setCheck(res)
      console.log('check', check) // returns []
    }
  }

Returns [] when I log in parent as well

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Instead of console logging it immediately, wait for it to change, because it's an async operation. You can wrap your log in a useEffect:

useEffect(() => {
    console.log(check);
}, [check]);
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!