umami/hooks/useConfig.js

26 lines
499 B
JavaScript
Raw Normal View History

import { useEffect } from 'react';
import useStore, { setConfig } from 'store/app';
import useApi from 'hooks/useApi';
2022-10-31 19:02:37 +01:00
let loading = false;
export default function useConfig() {
const { config } = useStore();
const { get } = useApi();
async function loadConfig() {
const { data } = await get('/config');
2022-10-31 19:02:37 +01:00
loading = false;
setConfig(data);
}
useEffect(() => {
2022-10-31 19:02:37 +01:00
if (!config && !loading) {
loading = true;
loadConfig();
}
}, []);
return config || {};
}