mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-01 05:30:40 +00:00
Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/3678180 * refactor: rax-provider * feat: add build command * chore: compilerOptions for rax-provider
29 lines
784 B
TypeScript
29 lines
784 B
TypeScript
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 });
|
|
}
|