otterscan/src/useConfig.ts

26 lines
598 B
TypeScript
Raw Normal View History

2021-07-08 19:02:42 +00:00
import { useState, useEffect } from "react";
export type OtterscanConfig = {
erigonURL: string;
};
2021-07-09 05:07:20 +00:00
export const useConfig = (): [boolean?, OtterscanConfig?] => {
2021-07-08 19:02:42 +00:00
const [configOK, setConfigOK] = useState<boolean>();
const [config, setConfig] = useState<OtterscanConfig>();
useEffect(() => {
const readConfig = async () => {
const res = await fetch("/config.json");
if (res.ok) {
const _config: OtterscanConfig = await res.json();
setConfig(_config);
setConfigOK(res.ok);
}
};
readConfig();
}, []);
return [configOK, config];
};