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
theme
useTheme
import type { Metadata } from 'next'; import localFont from 'next/font/local'; import { ThemeProvider } from '@/components/ThemeProvider'; // ... export default function RootLayout({ children, }: { children: React.ReactNode; }) { return ( <html lang='en' suppressHydrationWarning> <body className={cn( 'bg-background font-sans antialiased', interFont.variable, )} > <LayoutHeader /> <ThemeProvider attribute='class' defaultTheme='system' disableTransitionOnChange > <main className='p-4'>{children}</main> </ThemeProvider> </body> </html> ); }
// ThemeProvider 'use client'; import { ThemeProvider as NextThemesProvider } from 'next-themes'; import { type ThemeProviderProps } from 'next-themes/dist/types'; import * as React from 'react'; export function ThemeProvider({ children, ...props }: ThemeProviderProps) { return <NextThemesProvider {...props}>{children}</NextThemesProvider>; }
// LayoutHeader 'use client'; import { useTheme } from 'next-themes'; import * as React from 'react'; export default function LayoutHeader() { const { theme, setTheme } = useTheme(); return ( <header> <div> The current theme is: {theme} <button onClick={() => setTheme('light')}>Light Mode</button> <button onClick={() => setTheme('dark')}>Dark Mode</button> </div> </header> ); }
The text was updated successfully, but these errors were encountered:
just realized i didn't put the header in the provider 🤦
Sorry, something went wrong.
No branches or pull requests
theme
fromuseTheme
receives current theme as expected.The text was updated successfully, but these errors were encountered: