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.
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.
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">
<body>
<body class="dark-mode">
<body class="light-mode">
U can access it from getInitialProps inside _document
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.
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.
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">
U can access it from getInitialProps inside _document