UNPKG

@shopify/react-async

Version:

Tools for creating powerful, asynchronously-loaded React components.

31 lines (30 loc) 1.74 kB
import { Resolver } from '@shopify/async'; import { IfAllOptionalKeys } from '@shopify/useful-types'; import { AssetTiming, AsyncComponentType } from './types'; export 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']>; export 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']>; export 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']>; interface Options { immediate?: boolean; assets?: AssetTiming; styles?: AssetTiming; scripts?: AssetTiming; } export declare function useAsync<T>(resolver: Resolver<T>, { assets, scripts, styles, immediate }?: Options): { id: string | undefined; resolved: null; error: Error; loading: boolean; load: () => Promise<Error | T>; } | { id: string | undefined; resolved: T | null; error: null; loading: boolean; load: () => Promise<Error | T>; }; export declare function useAsyncAsset(id?: string, { scripts, styles }?: { styles?: AssetTiming; scripts?: AssetTiming; }): void; export {};