Next.js
Turning your Next.js app into a night owl? Follow this smooth guide to light up the dark mode magic.
Next Themes
Because you are using Next.js, you can use next-themes to implement dark mode.
npm i next-themes
Theme Provider
Next, you need to create a theme provider component. You can do it like this:
Since you've got the theme provider in play, you'll probably wanna team it up with a route provider. Go ahead and whip up a providers.tsx
file in your components
folder.
Usage
After that, you can use it in your root layout file like so:
Theme Switcher
For theme switcher, you can use the useTheme
hook from next-themes
to get the current theme.
npm i hq-icons
Next you can create component theme-switcher.tsx