useTheme
The useTheme
hook is a powerful tool that allows you to access the currently active theme object, the active color mode, and provides a function to switch the active color mode. This hook is essential for dynamically adjusting the appearance of your application based on the user's preferred color scheme.
#
Importimport { useTheme } from "pearl-ui";
#
Return ValuesThe useTheme
hook returns an object containing the following properties:
Name | Type | Description |
---|---|---|
theme | The theme configuration object for the currently active color mode. | |
colorMode | The currently active color mode. | |
toggleColorMode | A function that toggles the active color mode between light and dark. | |
switchColorMode | A function that allows you to switch the active color mode to a specific mode. |
#
How to UseHere's an example of how you can use the useTheme
hook in your application:
const { theme, colorMode, toggleColorMode, switchColorMode } = useTheme();