import React from 'react' interface Config { apiUrl: string } async function loadConfig(): Promise { const response = await fetch('./config.json') const config = await response.json() return config } let _configPromise: Promise = loadConfig() let _configCache: null | Config = null export function useConfig() { const [config, setConfig] = React.useState(_configCache) React.useEffect(() => { if (!_configCache) { _configPromise.then(setConfig) } }, []) return config } export default _configPromise