[PUI] Helper to render an instance for an url (#5977)

* added helper to render an instance for an url

* cleanup unsued imports
This commit is contained in:
Matthias Mair 2023-11-27 00:53:41 +01:00 committed by GitHub
parent e9fe394d94
commit 87df9245eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,33 @@
import { Loader } from '@mantine/core';
import { useMemo, useState } from 'react';
import { api } from '../../App';
import { ModelType } from '../../enums/ModelType';
import { RenderInstance } from './Instance';
/**
* Render a model instance from a URL
* @param model Model type
* @param url URL to fetch instance from
* @returns JSX Element
*/
export function InstanceFromUrl({
model,
url
}: {
model: ModelType;
url: string;
}) {
const [data, setData] = useState<any>(null);
useMemo(
() =>
api.get(url).then((res) => {
setData(res.data);
}),
[model, url]
);
if (!data) return <Loader />;
return <RenderInstance instance={data} model={model} />;
}