mirror of
https://github.com/kremalicious/umami.git
synced 2024-06-25 02:36:25 +02:00
29 lines
575 B
TypeScript
29 lines
575 B
TypeScript
import { useEffect } from 'react';
|
|
import useStore, { setConfig } from 'store/app';
|
|
import useApi from 'components/hooks/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;
|