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

174
Visualizações
How do I refresh parent component when I successfully make API call from child component, which is a modal?

I have home page with a table having few entries. Above table I have button called add entry. When user clicks on add entry, it opens a modal, where user can add few details and submit it. The submit button makes API call to store the data in database. Once the API call is successful, the modal closes. Now , how do I refresh the parent component after modal closes so that the newly added data can be shown in table (which is loaded via API call). I'm using functional components. I'm looking for steps that I should follow, not full code (pseudo code will do ). I'm not using redux. i dont want to do winow.reload(). as it reloads the whole page.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

make an async fetchData function that will fetch you table data all you have passed that fetchData function to modal and on success call that fetch function

const [loading,setLoading] = useState(false)
const [data,setData] = useState()

  const fetchPlans = async () => {
    try {
      setLoading(true);
      const getDataRes = await getData();
      // save that data in state that will reredener page
      setData(getDataRes.data);
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
    } catch (error) {
      console.log(error)
    } finally {
    setLoading(false);
    }  
   };
</>
about 4 years ago · Juan Pablo Isaza Relatório

0

You can create a callback function in the parent component and pass it to children component as a property

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