Dark/Light Mode
Stack components support light and dark mode out of the box. All UI components automatically adapt their colors, shadows, and contrast levels based on the selected theme.
You can switch between light and dark mode using next-themes (or any other library that changes the data-theme
or class
to dark
or light
attribute of the html
element).
Here is an example of how to set up next-themes with Stack (find more details in the next-themes documentation):
- Install next-themes:
- Add the
ThemeProvider
to yourlayout.tsx
file:
- Build a color mode switcher component:
Now if you put the ColorModeSwitcher
component in your app, you should be able to switch between light and dark mode. There should be no flickering or re-rendering of the page after reloading.