useTheme hook
Usage
Pando provides a useTheme
hook to allow you to easily manage set and update the theme of your application. It also allows you to extend and customize themes to fit your needs.
Pando’s tokens require a parent theme of inkyBlue
to access color tokens within the design system. It also has two color mode options built in: data-color-mode="dark"
and data-color-mode="light"
that you can use to toggle light and dark mode on Pando’s tokens. This hook automatically caches the theme to the localStorage
Object so that your users will have it saved for as long as they keep the cache alive. 🎉
Examples
Reference
Parameters
initialMode
, initialTheme
: Optional string values of any of the CustomModes or CustomThemes offered or extended via Typescript.
Extending modes with Typescript
If you are a Typescript user and would like to extend the modes beyond the default options provided, pass in your modes as a type parameter.
Extending themes with Typescript
If you are a Typescript user and would like to extend the themes beyond the default options provided, pass in your themes as a type parameter.
Example usage in Component
Here is an example of how you might use useTheme
to manage theme toggling between light
and dark
mode in an App component.
Because the useTheme
hook is designed to update the localStorage
Object, it should only be used on the client side.
Troubleshooting
My theme or mode is not changing when I update it
Make sure you are using a theme name that is either a Pando theme or one that has been defined in your global CSS styling. Otherwise the hook is updating values that are not mapping to any existing styles.
- Make sure you have followed the Pando
- (To use Pando’s provided themes and modes) Make sure you are using the correct top level
- (If you are using a custom theme or mode) Make sure you have a theme defined in your CSS using