Custom hook for accessing theme context
Provides access to the current theme state and toggle function. Must be used within a ThemeProvider component.
Features:
When used outside of ThemeProvider
function MyComponent() { const { isDarkMode, toggleDarkMode } = useTheme(); return ( <button onClick={toggleDarkMode}> Current theme: {isDarkMode ? 'dark' : 'light'} </button> );} Copy
function MyComponent() { const { isDarkMode, toggleDarkMode } = useTheme(); return ( <button onClick={toggleDarkMode}> Current theme: {isDarkMode ? 'dark' : 'light'} </button> );}
The current theme context
Custom hook for accessing theme context
Provides access to the current theme state and toggle function. Must be used within a ThemeProvider component.
Features:
Throws
When used outside of ThemeProvider
Example