1 | import { ComponentType, LazyExoticComponent } from 'react';
|
2 | import { DefaultComponentImport, DefaultImport, Loadable } from '../types';
|
3 | interface ImportedShape<T> {
|
4 | imported?: T;
|
5 | error?: any;
|
6 | loading?: boolean;
|
7 | loadable: Loadable<any>;
|
8 | retry(): void;
|
9 | }
|
10 | interface HookOptions {
|
11 | import?: boolean;
|
12 | track?: boolean;
|
13 | }
|
14 | /**
|
15 | * react hook to wrap `import` with a tracker
|
16 | * used by {@link useImported}
|
17 | * @internal
|
18 | */
|
19 | export declare function useLoadable<T>(loadable: Loadable<T>, options?: HookOptions): {
|
20 | loadable: Loadable<T>;
|
21 | retry: () => void;
|
22 | update: import("react").Dispatch<import("react").SetStateAction<{}>>;
|
23 | };
|
24 | /**
|
25 | * short version of {@link useImported}
|
26 | * @param {Function} importer - an function with `import` inside it
|
27 | *
|
28 | * @return {Object}
|
29 | * - imported: if non empty - the data is loaded
|
30 | * - error: if non empty - there is an error
|
31 | * - loading: if true - then it's still loading
|
32 | * - loadable: the under laying reference
|
33 | * - retry: retry if case of failure
|
34 | *
|
35 | * @example
|
36 | * const { imported: Imported, loadable } = useImported(importer);
|
37 | * if (Imported) {
|
38 | * // yep, it's imported
|
39 | * return <Imported {...children} />;
|
40 | * }
|
41 | * // else throw resolution
|
42 | * throw loadable.resolution;
|
43 | */
|
44 | export declare function useImported<T>(importer: DefaultImport<T> | Loadable<T>): ImportedShape<T>;
|
45 | /**
|
46 | * The code splitting hook, the full version
|
47 | * @param {Function} importer - an function with `import` inside it
|
48 | * @param {Function} [exportPicker] - a "picker" of the export inside
|
49 | * @param {HookOptions} options
|
50 | * @param {Boolean} [options.import=true] - should the component be imported. Allow to defer execution.
|
51 | * @param {Boolean} [options.track=true] - allows disabling tracking of components, isolating them to SSR
|
52 | *
|
53 | * @return {Object}
|
54 | * - imported: if non empty - the data is loaded
|
55 | * - error: if non empty - there is an error
|
56 | * - loading: if true - then it's still loading
|
57 | * - loadable: the under laying reference
|
58 | * - retry: retry if case of failure
|
59 | *
|
60 | * @see if you dont need precise control consider(and loading Components) {@link useLazy}
|
61 | *
|
62 | * @example
|
63 | * const { imported: Imported, loadable } = useImported(importer, ({namedExport} => namedExport);
|
64 | * @example
|
65 | * const { imported: Imported, loadable } = useImported(importer);
|
66 | * if (Imported) {
|
67 | * // yep, it's imported
|
68 | * return <Imported {...children} />;
|
69 | * }
|
70 | * // else throw resolution
|
71 | * throw loadable.resolution;
|
72 | */
|
73 | export declare function useImported<T, K = T>(importer: DefaultImport<T> | Loadable<T>, exportPicker: undefined | ((x: T) => K), options?: HookOptions): ImportedShape<K>;
|
74 | /**
|
75 | * A mix of React.lazy and useImported - uses React.lazy for Component and `useImported` to track the promise
|
76 | * not "retry"-able
|
77 | * @see if you need precise control consider {@link useImported}
|
78 | * @example
|
79 | * const Component = useLazy(() => import('./MyComponent');
|
80 | * return <Component /> // throws to SuspenseBoundary if not ready
|
81 | */
|
82 | export declare function useLazy<T>(importer: DefaultComponentImport<T>): LazyExoticComponent<ComponentType<T>>;
|
83 | export {};
|