To enable runtime theme management, wrap your application in the ThemeProvider and use the useTheme hook to control or access the current theme state.
Setup Theme Provider
Wrap your main App component with ThemeProvider from @/lib/theme/ThemeProvider:
import { ThemeProvider } from '@/lib/theme/ThemeProvider';
function App() {
return (
<ThemeProvider defaultTheme="dark">
<YourAppContent />
</ThemeProvider>
);
}
Using Theme Context
Access theme, setTheme, and toggleTheme via the useTheme hook:
import { useTheme } from '@/lib/theme/ThemeProvider';
function MyComponent() {
const { theme, setTheme, toggleTheme } = useTheme();
return (
<button onClick={toggleTheme}>
Current theme: {theme}
</button>
);
}
import { ThemeProvider } from '@/lib/theme/ThemeProvider';
function App() {
return (
<ThemeProvider defaultTheme="dark">
<YourAppContent />
</ThemeProvider>
);
}
// In a component
import { useTheme } from '@/lib/theme/ThemeProvider';
function MyComponent() {
const { theme, setTheme, toggleTheme } = useTheme();
return <button onClick={toggleTheme}>{theme}</button>;