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

164
Views
How to setState with value returned by an async function

I am attempting to setState (adding an element to an array) following an async function call. However images is set with undefined. (Even though underlying function definitely returns with a value.)

How do I make sure my array is updated with value after return from async function concludes?

const [images, setImages] = useState([])
pickerResult.map(async (img) => {
    await handleImageUpload(img.uri)
    .then((url) => {
    setImages(images => [...images, url]);
    })               
})
useEffect(() => {
        console.log(images)
    }, [images])
Array [
  undefined,
  undefined,
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this:

const [images, setImages] = useState([])
pickerResult.map(async (img) => {
    const url = await handleImageUpload(img.uri)
    setImages(images => [...images, url]);              
})
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!