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 ?