hooks icon indicating copy to clipboard operation
hooks copied to clipboard

[RFC] useTheme

Open ianzone opened this issue 1 year ago • 0 comments

功能

  1. 设置主题模式并将其存储在 localStorage 中
  2. 监听系统主题
  3. 当主题模式为 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

ianzone avatar Aug 05 '24 02:08 ianzone