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

150
Visualizações
React - How to notify child component which uses a props-rest-call-function that REST-call has resolved?

When I submit an object/issue I am calling a function of the parent component, which has been passed to the child component as props. After sending my data I want to clear my input fields. The Problem is, that I am clearing my input fields immediately after calling addNewIssue(). I actually want to wait until the POST-Call has resolved.

If I only had one component I could just clear the input fields after e.g. setissueList(newIssueList), since state and rest-call would be in the same component.

How can I notify the child component that the POST-Call has resolved and only then it should clear the inputs?

I tried to google this problem, but I couldn't find anything. Most likely I am not using the right words. I assume it has to do something with promises and the solution might be simple but I am not an expert regarding promises or async.

// parent component
const addNewIssue = (issue) => {
  axios.post(url + '/forms/issue', issue, headers).then((res) => {
    let newIssueList = [...issueList, res.data];
    setissueList(newIssueList);
  });
}

<NewIssue addNewIssue={addNewIssue} />


// child component
const const handleSubmit = (e) => {
  e.preventDefault();
  addNewIssue(inputs);
  setInputs({
    summary: "",
    description: ""
   });
 } 
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Use your API request along with a callback

// parent component
const addNewIssue = (issue,cb) => {
  axios.post(url + '/forms/issue', issue, headers).then((res) => {
    let newIssueList = [...issueList, res.data];
    setissueList(newIssueList);
    cb()
  });
}

<NewIssue addNewIssue={addNewIssue} />


// child component
const const handleSubmit = (e) => {
  e.preventDefault();
const cb=()=>{setInputs({
    summary: "",
    description: ""
   });}
  addNewIssue(inputs,cb);
  
 } 
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