Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda