Files
umami/src/components/hooks/queries/useConfig.ts
T
2024-02-02 22:20:13 -08:00

30 lines
578 B
TypeScript

'use client';
import { useEffect } from 'react';
import useStore, { setConfig } from 'store/app';
import { useApi } from './useApi';
let loading = false;
export function useConfig() {
const { config } = useStore();
const { get } = useApi();
const configUrl = process.env.configUrl;
async function loadConfig() {
const data = await get(configUrl);
loading = false;
setConfig(data);
}
useEffect(() => {
if (!config && !loading && configUrl) {
loading = true;
loadConfig();
}
}, []);
return config;
}
export default useConfig;