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

199
Vistas
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 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