loading...

Discussion on: How to Learn Next.js in 2020

Collapse
ombratteng profile image
Ole-Martin Bratteng

All I want to know is, how can I check for a cookie and then set a class on the body, based on the cookie, server side.

Collapse
arunoda profile image
Arunoda Susiripala Author

You can do that inside getServerSideProps. Basically you have access to the request object. Then get the cookie. After that return it as a prop.

Collapse
ombratteng profile image
Ole-Martin Bratteng

Is that available in _document.js? That's where I want to set the class of <body>.
So that the html sent from the server, either has <body class="dark-mode"> or <body class="light-mode">

Thread Thread
nimitwalia89 profile image
nimit walia

U can access it from getInitialProps inside _document