hooks
hooks copied to clipboard
[RFC] useTheme
功能
- 设置主题模式并将其存储在 localStorage 中
- 监听系统主题
- 当主题模式为
system时返回当前系统主题,否则返回当前主题模式
API
type ThemeModeType = 'light' | 'dark' | 'system';
function useTheme(): {
theme: "light" | "dark";
themeMode: ThemeModeType;
setThemeMode: (mode: ThemeModeType) => void;
}
使用场景
在全局上下文中使用 theme 指示当前主题,在子组件中使用 setThemeMode 设置主题模式。
PR
https://github.com/alibaba/hooks/pull/2617