manifold/web/hooks/use-global-config.ts

18 lines
547 B
TypeScript
Raw Normal View History

import { GlobalConfig } from 'common/globalConfig'
import { useEffect } from 'react'
import { listenForGlobalConfig } from 'web/lib/firebase/globalConfig'
import { inMemoryStore, usePersistentState } from './use-persistent-state'
export const useGlobalConfig = () => {
const [globalConfig, setGlobalConfig] =
usePersistentState<GlobalConfig | null>(null, {
store: inMemoryStore(),
key: 'globalConfig',
})
useEffect(() => {
2022-10-12 22:39:13 +00:00
return listenForGlobalConfig(setGlobalConfig)
}, [setGlobalConfig])
return globalConfig
}