mirror of
https://github.com/fankes/komari-theme-purcarte.git
synced 2025-12-14 21:41:20 +08:00
fix: 修复 tags 无法解析颜色的问题
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useContext } from "react";
|
||||
import type { ConfigOptions } from "./default";
|
||||
import { ConfigContext } from "./ConfigContext";
|
||||
import { DEFAULT_CONFIG } from "./default";
|
||||
|
||||
/**
|
||||
* 使用全局配置 Hook,用于获取当前应用配置
|
||||
@@ -13,13 +14,14 @@ export function useAppConfig(): ConfigOptions {
|
||||
/**
|
||||
* 使用特定配置项 Hook,直接获取某个配置项的值
|
||||
* @param key 配置项键名
|
||||
* @returns 配置项的值
|
||||
* @returns 配置项的值,如果为 undefined 则返回默认配置中的值
|
||||
*/
|
||||
export function useConfigItem<K extends keyof ConfigOptions>(
|
||||
key: K
|
||||
): ConfigOptions[K] {
|
||||
): NonNullable<ConfigOptions[K]> {
|
||||
const config = useContext(ConfigContext);
|
||||
return config[key];
|
||||
// 如果配置项为 undefined,则回退到默认配置
|
||||
return (config[key] ?? DEFAULT_CONFIG[key]) as NonNullable<ConfigOptions[K]>;
|
||||
}
|
||||
|
||||
// 导出配置类型
|
||||
|
||||
Reference in New Issue
Block a user