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
"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 à 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