-
-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add useColorMode
function that waits for mount before returning resolved theme
#65
Comments
How is this better than returning |
I think returning undefined in What about adding an argument 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 |
If you already know the default theme... why not just use it directly? const { theme = 'light', setTheme } = useTheme() This way if |
Closing because I think your use-case should be solved with the above, and I don't think another hook will help here. |
Currently
useTheme
does not wait for react mount before returning the resolved themeThis means that in the following example
resolvedTheme
will be different between server and client, which will cause the react rehydration mismatch errorThere could be another function that waits for react mount before changing the theme on client, to prevent these react errors, something like this
I can make a PR if you agree
The text was updated successfully, but these errors were encountered: