mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
25 lines
478 B
JavaScript
25 lines
478 B
JavaScript
|
import { useEffect } from 'react';
|
||
|
import useStore, { setConfig } from 'store/app';
|
||
|
import useApi from 'hooks/useApi';
|
||
|
|
||
|
let fetched = false;
|
||
|
|
||
|
export default function useConfig() {
|
||
|
const { config } = useStore();
|
||
|
const { get } = useApi();
|
||
|
|
||
|
async function loadConfig() {
|
||
|
const { data } = await get('/config');
|
||
|
setConfig(data);
|
||
|
}
|
||
|
|
||
|
useEffect(() => {
|
||
|
if (!config && !fetched) {
|
||
|
fetched = true;
|
||
|
loadConfig();
|
||
|
}
|
||
|
}, []);
|
||
|
|
||
|
return config || {};
|
||
|
}
|