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

169
Vistas
"OnThisDay" feature with Nextjs using getServerSideProps with Date.now() at runtime

I'm trying to implement a "OnThisDay" Wikipedia style feature with Nextjs, showing an event that happened on that day. For this I have a function that looks like this:

const list = [{"dateOfDeath": "2000-01-01", "name": "X"},{"dateOfDeath": "2000-01-02", "name": "Y"]

const dateObj = new Date();
const currentDay =
  ('0' + (dateObj.getMonth() + 1)).slice(-2) +
  '-' +
  ('0' + dateObj.getDate()).slice(-2);

export default function GetToday() {
  return list.filter(
    (person) => person.dateOfDeath.slice(5) === currentDay
  );
}

I'm then getting this via getStaticProps:

export const getStaticProps: GetStaticProps = async () => {
  const today = GetToday();
  return {
    props: {
      today
    },
    revalidate: 10
  };
};

This all works fine and well, however it seems that the Date object is created once at build time, so the page is stuck with whatever date the site was build on. I purposfully set revalidate to 10s trying to solve this, which didn't work. I also tried using getServerSideProps instead but that didn't change anything either. I'm deploying the site with Docker, using pretty much the Docker template of the Nextjs repo.

Does someone know a way, that a new Date object is created at runtime?

about 4 years ago · Juan Pablo Isaza
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