I currently have a black friday page. Only when this black friday page is expired (must get the expired date from a query before) do i want it to query the expired page data.
Essentially i'm looking to make the query more efficient. Where the expired data wouldn't be pulled for no reason, and vice versa (page data query if expired). If any of this is possible.
The only working code i have is to query both data (black friday page and expired page data)
export async function getStaticPaths() {
const blackFridaylugs = await ContentfulApi.getBlackFridaySlugs();
const paths = blackFridaySlugs.map((item) => ({
params: { slug: item.slug }
}));
return {
paths,
fallback: "blocking"
};
}
export async function getStaticProps({ preview = false, params, previewData }) {
const page = await ContentfulApi.getBlackFridayPromoBySlug(params.slug, {
preview,
enviroment: previewData?.enviroment
});
const expiredPage = await ContentfulApi.getPageContentBySlug(
"expired-page",
{
preview,
enviroment: previewData?.enviroment
}
);
const globalSettings = await ContentfulApi.getGlobalSettings({ preview });
return {
props: {
page,
expiredPage,
globalSettings
},
revalidate: 100
};
}
function BlackFridayPages({ page, expiredPage, globalSettings }) {
const [expired, setExpired] = useState(false);
const promoExpired = new Date() - new Date(page?.promoEnd) < 0;
useEffect(() => {
if (promoExpired) {
setExpired(false);
} else {
setExpired(true);
}
}, [promoExpired]);
if (!expired)
return (
<ExpiredPage expiredPage={expiredPage} />
);
return (
<>
<BlackFridayPage />
</>
);
}
export default BlackFridayPages;