import React, { DependencyList, useState } from "react"; import { Spinner } from "@patternfly/react-core"; import { useFetch } from "../../context/auth/AdminClient"; type DataLoaderProps = { loader: () => Promise; deps?: DependencyList; children: ((arg: T) => any) | React.ReactNode; }; export function DataLoader(props: DataLoaderProps) { const [data, setData] = useState(); useFetch( () => props.loader(), (result) => setData(result), props.deps || [] ); if (data) { if (props.children instanceof Function) { return props.children(data); } return props.children; } return (
); }