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

200
Visualizações
Next.js conditional page rendering

Is is possible with next.js to server side render different pages or components based on certain conditions.

E.g. I would like to create a page that shows a complete different component for every day of the year. So on server side i would like to get the current date and based on this one render a certain component on the client side.

For testing i created following code:

export default function Home({seconds}: { seconds: number}) {
  if (seconds >= 30) {
    return (
      <h1 className="text-3xl font-bold underline">
        Hello Silvia
      </h1>
    )    
  } else {
    return (
      <h1 className="text-3xl font-bold underline">
        Hello Thomas!
      </h1>
    )
  }
}

export async function getServerSideProps(context: any) {
  const now = new Date()
  
  return {
    props: {
      seconds: now.getSeconds()
    },
  }
}

In general this is working but the if statement inside of the Home component is executed on the client side. So a user could easily manipulate the seconds variable. Is there a way to archive this on server side ?

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