Hooks
useDarkMode
Easily toggle between dark and light themes with useDarkMode.
Install
npm
Description
The useDarkMode
hook provides a simple way to toggle between dark and light themes in your application. It manages the theme state and automatically applies the appropriate class to the body element, ensuring that the entire page reflects the selected theme. This is particularly useful for adding dark mode support to your application with minimal setup.
Parameters
This hook does not require any parameters.
Return Values
Name | Type | Description |
---|---|---|
isDarkMode | boolean | A boolean indicating whether the dark mode is currently active (true for dark mode, false for light mode). |
toggleTheme | () => void | A function to toggle between dark and light themes. This also updates the body tag’s class name to reflect the current theme. |
Example
useDarkMode.example.tsx