mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-17 04:22:28 +00:00
29 lines
784 B
JavaScript
29 lines
784 B
JavaScript
import { createElement, useState, useEffect } from 'rax';
|
|
import { app } from '@ali/lowcode-runtime';
|
|
|
|
export default function LazyComponent(props) {
|
|
const [schema, setSchema] = useState(null);
|
|
|
|
useEffect(() => {
|
|
(async () => {
|
|
const { getPageData } = props || {};
|
|
if (getPageData && !schema) {
|
|
const data = await getPageData();
|
|
setSchema(data);
|
|
}
|
|
})();
|
|
});
|
|
|
|
const { getPageData, ...restProps } = props || {};
|
|
const Renderer = app.getRenderer();
|
|
const Loading = app.getLoading();
|
|
if (!Renderer || !schema) {
|
|
if (!Loading) {
|
|
return null;
|
|
}
|
|
// loading扩展点
|
|
return createElement(Loading);
|
|
}
|
|
return createElement(Renderer, { schema, loading: Loading ? createElement(Loading) : null, ...restProps });
|
|
}
|