We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I am unable to set the theme using setTheme. Here's a link for minimal example.
Any pointer will be helpful.
My ThemeSwitch is a dropdown which logs the output to browser console:
// app/components/ThemeSwitch.tsx "use client"; import { useState, useEffect } from 'react' import { useTheme } from 'next-themes' const ThemeSwitch = () => { const [ mounted, setMounted ] = useState(false) const { theme, setTheme, resolvedTheme } = useTheme() useEffect(() => { setMounted(true) }, []) if (!mounted) return null; const handleChange = (e : string) => { console.log(e); console.log('before ', theme, ' ', resolvedTheme); setTheme(e); console.log('after ', theme, ' ', resolvedTheme); } return ( <select value={theme} onChange={e => handleChange(e.target.value)}> <option value="system">System</option> <option value="dark">Dark</option> <option value="light">Light</option> </select> ) } export default ThemeSwitch
My app/layout.tsx:
export default function RootLayout({ children, }: { children: React.ReactNode }) { return ( <html lang="en" suppressHydrationWarning> <body className="bg-white dark:bg-black min-h-dvh"> <ThemeProvider attribute="data-theme" enableSystem defaultTheme="system" value={{ light: 'light', dark: 'dark' }} > {children} </ThemeProvider> </body> </html> ) }
Output Image:
The text was updated successfully, but these errors were encountered:
It seems to work now, thanks to this comment.
Putting Providers in a separate file and importing it works.
Sorry, something went wrong.
No branches or pull requests
I am unable to set the theme using setTheme. Here's a link for minimal example.
Any pointer will be helpful.
My ThemeSwitch is a dropdown which logs the output to browser console:
My app/layout.tsx:
Output Image:
The text was updated successfully, but these errors were encountered: