Document test9 tag 2026-11-02 for upload; POST config pull + WS, fixed dark home, no debug bar. Co-authored-by: Cursor <cursoragent@cursor.com>
28 lines
800 B
TypeScript
28 lines
800 B
TypeScript
import { useEffect, useState } from 'react'
|
|
import type { NomadroRemoteConfig } from '@/data/remoteConfig.defaults'
|
|
import {
|
|
getCachedRemoteConfig,
|
|
loadRemoteConfig,
|
|
subscribeRemoteConfig,
|
|
} from '@/services/remoteConfig'
|
|
|
|
/** 页面级:订阅远程配置,后台开关约 2s 内热更新 */
|
|
export function useRemoteConfig() {
|
|
const [config, setConfig] = useState<NomadroRemoteConfig>(() => getCachedRemoteConfig())
|
|
const [fromOffline, setFromOffline] = useState(false)
|
|
|
|
useEffect(() => {
|
|
const unsub = subscribeRemoteConfig((r) => {
|
|
setConfig(r.config)
|
|
setFromOffline(r.fromOffline)
|
|
})
|
|
void loadRemoteConfig(true).then((r) => {
|
|
setConfig(r.config)
|
|
setFromOffline(r.fromOffline)
|
|
})
|
|
return unsub
|
|
}, [])
|
|
|
|
return { config, fromOffline }
|
|
}
|