-2
Hello, I am using React with Next.js and using the native Next.js method, getServerSideProps to retrieve browser cookies.
It turns out that the breakdown works for the first const, but not for the last.
export const getServerSideProps: GetServerSideProps = async(ctx) => {
const { level, currentExperience, challengesCompleted, user, userName, accumulatedExperience} = ctx.req.cookies;
return {
props: {
level: Number(level ?? 1),
currentExperience: Number(currentExperience ?? 0),
challengesCompleted: Number(challengesCompleted ?? 0),
user: user || null,
userName: userName || null,
accumulatedExperience: Number(accumulatedExperience ?? 0)
}
};
}
In the case, level, currentExperience and challengesCompleted are returning me correctly 0. user and username, rightfully null
But accumulatedExperience turning back undefined
and this makes the mathematical operations are not performed, because returns me Nan.
Does anyone know what it can be ?
I ended up solving here still with getServerSideProps, but I will make this change since it does not make much sense to capture cookies using SSR. Thank you.
– Marcos Leonardo Martins