amis/examples/components/LazyData.tsx
liaoxuezhi 84f5a08c52
Echarts 配置功能
* 添加 datamapping 功能

* echarts dataMapping 不处理function

* 配置改成异步加载

* 添加 打包
2020-12-17 18:16:29 +08:00

18 lines
381 B
TypeScript

import React from 'react';
export function lazyData<T, U>(
getData: () => Promise<U>,
getComponent: (
data: U
) => React.ComponentType<T> | Promise<React.ComponentType<T>>
) {
return React.lazy(async () => {
const data = await getData();
let component = await getComponent(data);
return {
default: component as React.ComponentType<T>
};
});
}