umami/hooks/useConfig.js
2023-05-17 23:20:06 -07:00

28 lines
514 B
JavaScript

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