mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
18 lines
381 B
TypeScript
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>
|
||
|
};
|
||
|
});
|
||
|
}
|