UNPKG

@lesnoypudge/utils-react

Version:

lesnoypudge's utils-react

65 lines (64 loc) 3.06 kB
import { Types } from './types'; declare class LazyLoad { constructor(); /** * Creates a group of components that is loaded together * when one of them is called. * Loading is resolved when all components is loaded. * Throws error if called component is failed to load. */ createPreloadGroup(options?: Types.createPreloadGroup.Options): Types.createPreloadGroup.Return; /** * Creates a group of components that starts loading when * one of them is called. * Loading is resolved as soon as called component is loaded. * Other components is loaded in background. */ createAsyncLoadGroup(options?: Types.asyncRetry.Options): { withAsyncLoadGroup: <_Component extends Types.BaseComponent>(factory: Types.PromiseModuleFactory<_Component>) => Types.ModuleOrPromiseModuleFactory<_Component>; }; /** * Wraps a component loading function to add additional * delay before loading in dev mode. */ withDelay<_Component extends Types.BaseComponent>(factory: Types.PromiseModuleFactory<_Component>, options?: Types.withDelay.Options): () => Promise<{ default: _Component; }>; /** * Original React.lazy will cache rejected state and * refuse to try to load again. * This version modifies how internal cache works by not * remembering rejected state. * Source of React.lazy: https://github.com/facebook/react/blob/main/packages/react/src/ReactLazy.js * Abandoned (2019) pull request with similar solution: https://github.com/facebook/react/pull/15296 */ modifiedReactLazy: <_Component extends Types.BaseComponent>(factory: Types.ModuleOrPromiseModuleFactory<_Component>) => import('react').LazyExoticComponent<_Component>; /** * Wrapper for basic lazy component. */ baseComponent<_Component extends Types.BaseComponent>(factory: Types.PromiseModuleFactory<_Component>, options?: Types.withDelay.Options): import('react').LazyExoticComponent<_Component>; /** * Creates predefined wrapper for preloaded components. */ createBasePreloadedComponent(options?: Types.createBasePreloadedComponent.Options): Types.createBasePreloadedComponent.Return; /** * Creates predefined wrapper for async components. */ createBaseAsyncLoadedComponent(options?: { delay?: Types.withDelay.Options; retry?: Types.asyncRetry.Options; }): <_Component extends Types.BaseComponent>(factory: Types.PromiseModuleFactory<_Component>) => import('react').LazyExoticComponent<_Component>; /** * Predefined wrapper for preloaded components. */ basePreloadedComponent: Types.createBasePreloadedComponent.Return; /** * Predefined wrapper for async components. */ baseAsyncComponent: <_Component extends Types.BaseComponent>(factory: Types.PromiseModuleFactory<_Component>) => import('react').LazyExoticComponent<_Component>; } /** * Utility functions for managing lazy-loaded components. */ export declare const lazyLoad: LazyLoad; export {};