UNPKG

@caixue/react-loadable

Version:

A higher order component for loading components with dynamic imports.Support vite and webpack.

61 lines (60 loc) 2.71 kB
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>; } export default function Loadable<T = any>(option: IpProps<T> | (() => asyncCom<T>)): { new (props: any): { state: { isLoading: boolean; isError: boolean; isTimedOut: boolean; Component?: React.ElementType; }; /** '#' start means private property */ "__#1@#refPromise": Promise<any>; "__#1@#resolveRef": (value: any) => void; getComponent(): Promise<void>; componentDidMount(): Promise<void>; componentWillUnmount(): void; handleRes(res: any): void; /** get resolve component ref */ getRef(): Promise<any>; render(): React.JSX.Element; context: any; setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<T>) => {} | Pick<{}, K>) | Pick<{}, K>, callback?: () => void): void; forceUpdate(callback?: () => void): void; readonly props: Readonly<T> & Readonly<{ children?: React.ReactNode; }>; refs: { [key: string]: React.ReactInstance; }; shouldComponentUpdate?(nextProps: Readonly<T>, nextState: Readonly<{}>, nextContext: any): boolean; componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void; getSnapshotBeforeUpdate?(prevProps: Readonly<T>, prevState: Readonly<{}>): any; componentDidUpdate?(prevProps: Readonly<T>, prevState: Readonly<{}>, snapshot?: any): void; componentWillMount?(): void; UNSAFE_componentWillMount?(): void; componentWillReceiveProps?(nextProps: Readonly<T>, nextContext: any): void; UNSAFE_componentWillReceiveProps?(nextProps: Readonly<T>, nextContext: any): void; componentWillUpdate?(nextProps: Readonly<T>, nextState: Readonly<{}>, nextContext: any): void; UNSAFE_componentWillUpdate?(nextProps: Readonly<T>, nextState: Readonly<{}>, nextContext: any): void; }; contextType?: React.Context<any>; }; export {};