Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

258
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda