umami/hooks/useConfig.js

28 lines
514 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;
2023-05-18 08:20:06 +02:00
export 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 || {};
}
2023-05-18 08:20:06 +02:00
export default useConfig;