Build application shell with live runtime status
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { fetchRuntimeConfig } from "../../../lib/api/systemApi";
|
||||
import type { RuntimeConfig } from "../../../types/system";
|
||||
|
||||
export function useRuntimeConfig() {
|
||||
const [runtimeConfig, setRuntimeConfig] = useState<RuntimeConfig | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetchRuntimeConfig()
|
||||
.then((data) => {
|
||||
setRuntimeConfig(data);
|
||||
setError(null);
|
||||
})
|
||||
.catch((exception: unknown) => {
|
||||
setError(
|
||||
exception instanceof Error
|
||||
? exception.message
|
||||
: "Failed to fetch runtime config.",
|
||||
);
|
||||
})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return {
|
||||
runtimeConfig,
|
||||
loading,
|
||||
error,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user