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