Comments (4)
How is this better than returning undefined
, as the hook currently does? It's documented in the README that you need to be careful about hydration mismatch: https://github.com/pacocoursey/next-themes#avoid-hydration-mismatch
from next-themes.
I think returning undefined in useTheme
is not really helpful, i cannot use useTheme
directly without using first useMount
What about adding an argument defaultTheme
to useTheme
?
import { useTheme } from 'next-themes'
const ThemeChanger = () => {
const { theme, setTheme } = useTheme({ defaultTheme: 'light' })
return (
<div>
The current theme is: {theme}
<button onClick={() => setTheme('light')}>Light Mode</button>
<button onClick={() => setTheme('dark')}>Dark Mode</button>
</div>
)
}
This would make things a lot easier
from next-themes.
If you already know the default theme... why not just use it directly?
const { theme = 'light', setTheme } = useTheme()
This way if theme
is undefined, it will become 'light'
instead :)
from next-themes.
Closing because I think your use-case should be solved with the above, and I don't think another hook will help here.
from next-themes.
Related Issues (20)
- `resolvedTheme` does not resolve to `dark` | `light` but instead to `system` HOT 1
- Support for multiple attributes (more in depth theme management)
- Flash of no theme (zero-config ThemeProvider, Next 14, not Cloudflare) HOT 1
- setTheme does not update DOM (next 13) HOT 1
- How can I get a transition between dark and light mode HOT 3
- defaultTheme did't work in the latest Chrome for macOS HOT 7
- 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
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.