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

257
Visualizações
Why data is not updating in NextJS?

I wondering why data is not updating while I make DELETE request? Should I change getServerSideProps to getStaticProps or there is other way how to solve this problem? In addition I don't want to reload page :)

const Component = ({ data }) => {

  return (
    <div>
      {data.map((el) => {
        return (
          <React.Fragment key={el._id}>
            <span>{el.visitorDate}</span>
            <span>{el.visitorName}</span>
            <span>{el.visitorFamilyName}</span>
            <div>
              <button
                onClick={async () => {
                  const res = await fetch(
                    `http://localhost:4000/api/visitorData/${el._id}`,
                    {
                      method: "DELETE",
                      headers: {
                        "Content-Type": "application/json",
                      },
                    }
                  );
                }}
              >
                DELETE
              </button>
            </div>
          </React.Fragment>
        );
      })}
    </div>
  );
};

export default Component;

export async function getServerSideProps(context) {
  const res = await fetch("http://localhost:4000/api/visitorData/");
  const data = await res.json();
  return {
    props: { data },
  };
}

If something is unclear, let me know :)

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

0

You have to update the data after the DELETE request to see your changes.

Either handle this manually in onClick, or add router.refresh() after the fetch.

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