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

228
Views
Where am I going wrong with returning an array from a react function

So I have a react function that is a api call ad gets some data, I want to just return the status of that back to the parent component.

Here is my code

Parent component function

//this is called via a button with a state passed down to the function
    async function scheduleParent(){
        const returned = await ScheduleChild(data)
        console.log(returned)
    }

Child function

export default async function ScheduleChild(data){
await axios({
        method: "POST",
        url: //myapi,
        data: {data}
    }).then(res => {
        console.log(res)
        return(res)
    }).catch(err => {
        console.log(err)
        return(err)
    });  

I am getting undefined when console.log(returned) is called.

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

0

You are returning from the callback function and not from the SchedulePayment . You should add return before your api call in order to work. Or in a nicer way

export default async function SchedulePayment(data){
  try {
    const res = axios.post(<api-url>, data)
    return res
  } catch (err) {
    console.log(err)
    return(err)
  }
}
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!