Set class to body on first render SSR [Page router]
Unanswered
Lhasa Apso posted this in #help-forum
Lhasa ApsoOP
Is it possible with Next to set the
Can I set this value to a body on first render instead of this current solution where I set it on client (in
Code:
class attribute on first render? Let's say the siteTheme variable will be provided from getServerSideProps so I'll get this value from server.Can I set this value to a body on first render instead of this current solution where I set it on client (in
useEffect). This solution causes small flash before class gets applied on the client.Code:
useEffect(() => {
document.body.classList.add(siteTheme);
}, [siteTheme]);
export const getServerSideProps = () => {
return { props: { siteTheme: "red" } };
}