UNPKG

@shopify/react-async

Version:

Tools for creating powerful, asynchronously-loaded React components

52 lines 2.15 kB
import type { Resolver } from '@shopify/async'; import type { IfAllOptionalKeys, NoInfer } from '@shopify/useful-types'; import type { AssetTiming, AsyncComponentType } from './types'; export type Preloadable<PreloadOptions extends object> = Pick<AsyncComponentType<any, any, PreloadOptions, any, any>, 'usePreload'>; export type Prefetchable<PrefetchOptions extends object> = Pick<AsyncComponentType<any, any, any, PrefetchOptions, any>, 'usePrefetch'>; export type KeepFreshable<KeepFreshOptions extends object> = Pick<AsyncComponentType<any, any, any, any, KeepFreshOptions>, 'useKeepFresh'>; export declare function usePreload<PreloadOptions extends object>(...args: IfAllOptionalKeys<PreloadOptions, [ Preloadable<PreloadOptions>, PreloadOptions? ], [ Preloadable<PreloadOptions>, NoInfer<PreloadOptions> ]>): ReturnType<(typeof args)[0]['usePreload']>; export declare function usePrefetch<PrefetchOptions extends object>(...args: IfAllOptionalKeys<PrefetchOptions, [ Prefetchable<PrefetchOptions>, PrefetchOptions? ], [ Prefetchable<PrefetchOptions>, NoInfer<PrefetchOptions> ]>): ReturnType<(typeof args)[0]['usePrefetch']>; export declare function useKeepFresh<KeepFreshOptions extends object>(...args: IfAllOptionalKeys<KeepFreshOptions, [ KeepFreshable<KeepFreshOptions>, KeepFreshOptions? ], [ KeepFreshable<KeepFreshOptions>, NoInfer<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<T | Error>; } | { id: string | undefined; resolved: T | null; error: null; loading: boolean; load: () => Promise<T | Error>; }; export declare function useAsyncAsset(id?: string, { scripts, styles }?: { styles?: AssetTiming; scripts?: AssetTiming; }): void; export {}; //# sourceMappingURL=hooks.d.ts.map