@caixue/react-loadable
Version:
A higher order component for loading components with dynamic imports.Support vite and webpack.
29 lines (28 loc) • 969 B
TypeScript
import React from 'react';
interface LoadingProps {
isError?: boolean;
isTimedOut?: boolean;
isLoading?: boolean;
retry?: () => any | void;
}
type asyncCom<T = any> = Promise<{
default: React.FC<T> | React.ComponentClass<T> | React.PureComponent<T> | ((props: T, ...args: any[]) => any);
}>;
interface IpProps<T = any> {
loader: () => asyncCom<T>;
/** The lazy load time(ms); 延迟加载时间 单位毫秒 */
delay?: number;
/** timeout(ms); 超时设置 单位毫秒 */
timeout?: number;
/** loading compontent;加载过程组件 */
loading?: React.FC<LoadingProps> | React.ComponentClass<LoadingProps>;
}
declare class AsyncCom<T> extends React.Component<T> {
constructor(props: T);
getRef(): Promise<any>;
}
export default function Loadable<T = any>(option: IpProps<T> | (() => asyncCom<T>)): {
new (props: T): AsyncCom<T>;
contextType?: React.Context<any>;
};
export {};