Comments (2)
@pacocoursey - Thanks for your reply!
My web app has a combination of server side and client side rendering, and supports multiple themes. The user may have saved theme preference, which needs to be fetched.
If no themes preferences are present for the user, the app will rely on the system defaults.
You're right - maybe I don't need to use localStorage but its useful when it comes to propagating changes across tabs/sessions.
next-themes was really useful for the above reasons. Saved me from the task of building in all that logic.
If only it could support a way to set initial theme. For eg.
**<ThemeProvider initTheme="dark" attribute="class">**
Currently., I am fetching the preference on the server side and setting the theme (setTheme()) on the client side, which is causing the frontend to flash.
from next-themes.
Good question. Next-themes doesn't support this in a nice way right now, and it may not need to.
It sounds like you're server-rendering all your pages, so you can just include the theme as a body class with the initial HTML payload (getInitialProps in _document
I believe). Then you don't need localStorage or the render-blocking inline script that next-themes injects.
from next-themes.
Related Issues (20)
- Next Themes Flash of White BG when using the basePath HOT 4
- Inconsistent theming when the page loads HOT 3
- light/dark mode by changing class names on html tag HOT 2
- There is a error while setting up ThemeProvider HOT 5
- How to disable syncing themes between tabs HOT 2
- Documentation out of date with Tailwind's new dark-mode API
- Should `resolvedTheme` obey `forcedTheme`? HOT 3
- Allow nested providers HOT 2
- Theme object is injected into the "data-theme" property. HOT 1
- useTheme doesn't work in monorepo ui library. HOT 1
- `TypeError: Cannot read properties of undefined (reading 'addListener')` using `vitest`/`@testing-library/react` HOT 1
- Support for changing both class and data-theme attribute simultaneously HOT 1
- Callback Version of `setTheme` Passes Itself HOT 1
- Possibility to share across sub-domains? HOT 1
- ThemeProvider returns multiple types HOT 3
- setTheme not working HOT 1
- Theme flashing v0.3.0 HOT 6
- Next.js suspense triggered twice with next-themes HOT 1
- Flash Of Unstyled Content (FOUC) on Live Website HOT 6
- The way avoid hydration errors has a negative impact on SEO. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next-themes.