How to add dark/light mode to my next.js blog? #12171
-
I have started doing som web dev for my personal project and figuring out how to implmenet a dark mode for the next.js with styled-jsx. i haven't come across any exmaples. Any idea help me figure out this would be of great help. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
since styled-jsx uses interpolated css values you may be able to use the react state api to inject some main body/text colors at a high level. You may also have luck with a theming library that supports color modes- theme-ui which has this and a next.js example in its repository. |
Beta Was this translation helpful? Give feedback.
-
Here's an example using |
Beta Was this translation helpful? Give feedback.
-
Here is what I did in njt (npm jump to): kachkaev/njt@1ef3bb0
|
Beta Was this translation helpful? Give feedback.
Here is what I did in njt (npm jump to): kachkaev/njt@1ef3bb0
.dark-mode
/.light-mode
to body. I'm using these extra class names in styled-component styles, but the trick should also work in any other styling solution_document.tsx
useDarkMode()
is already used in_app.tsx