UNPKG

1.74 kBTypeScriptView Raw
1import { Resolver } from '@shopify/async';
2import { IfAllOptionalKeys } from '@shopify/useful-types';
3import { AssetTiming, AsyncComponentType } from './types';
4export declare function usePreload<PreloadOptions extends object>(...args: IfAllOptionalKeys<PreloadOptions, [AsyncComponentType<any, any, PreloadOptions, any, any>, PreloadOptions?], [AsyncComponentType<any, any, PreloadOptions, any, any>, PreloadOptions]>): ReturnType<typeof args[0]['usePreload']>;
5export declare function usePrefetch<PrefetchOptions extends object>(...args: IfAllOptionalKeys<PrefetchOptions, [AsyncComponentType<any, any, any, PrefetchOptions, any>, PrefetchOptions?], [AsyncComponentType<any, any, any, PrefetchOptions, any>, PrefetchOptions]>): ReturnType<typeof args[0]['usePrefetch']>;
6export declare function useKeepFresh<KeepFreshOptions extends object>(...args: IfAllOptionalKeys<KeepFreshOptions, [AsyncComponentType<any, any, any, any, KeepFreshOptions>, KeepFreshOptions?], [AsyncComponentType<any, any, any, any, KeepFreshOptions>, KeepFreshOptions]>): ReturnType<typeof args[0]['useKeepFresh']>;
7interface Options {
8 immediate?: boolean;
9 assets?: AssetTiming;
10 styles?: AssetTiming;
11 scripts?: AssetTiming;
12}
13export declare function useAsync<T>(resolver: Resolver<T>, { assets, scripts, styles, immediate }?: Options): {
14 id: string | undefined;
15 resolved: null;
16 error: Error;
17 loading: boolean;
18 load: () => Promise<Error | T>;
19} | {
20 id: string | undefined;
21 resolved: T | null;
22 error: null;
23 loading: boolean;
24 load: () => Promise<Error | T>;
25};
26export declare function useAsyncAsset(id?: string, { scripts, styles }?: {
27 styles?: AssetTiming;
28 scripts?: AssetTiming;
29}): void;
30export {};