UNPKG

@shopify/react-async

Version:

Tools for creating powerful, asynchronously-loaded React components

32 lines 2.02 kB
import type { ReactNode, ComponentType } from 'react'; import type { ResolverOptions } from '@shopify/async'; import { DeferTiming } from '@shopify/async'; import type { AsyncComponentType } from './types'; interface Options<Props extends object, PreloadOptions extends object = {}, PrefetchOptions extends object = {}, KeepFreshOptions extends object = {}> extends ResolverOptions<ComponentType<Props>> { defer?: DeferTiming | ((props: Props) => boolean); deferHydration?: DeferTiming | ((props: Props) => boolean); displayName?: string; renderLoading?(props: Props): ReactNode; renderError?(error: Error): ReactNode; /** * Custom logic to use for the usePreload hook of the new, async * component. Because this logic will be used as part of a generated * custom hook, it must follow the rules of hooks. */ usePreload?(props: PreloadOptions): () => void; /** * Custom logic to use for the usePrefetch hook of the new, async * component. Because this logic will be used as part of a generated * custom hook, it must follow the rules of hooks. */ usePrefetch?(props: PrefetchOptions): () => void; /** * Custom logic to use for the useKeepFresh hook of the new, async * component. Because this logic will be used as part of a generated * custom hook, it must follow the rules of hooks. */ useKeepFresh?(props: KeepFreshOptions): () => void; } export declare function createAsyncComponent<Props extends object, PreloadOptions extends object = {}, PrefetchOptions extends object = {}, KeepFreshOptions extends object = {}>({ id, load, defer, deferHydration, displayName, renderLoading, renderError, usePreload: useCustomPreload, usePrefetch: useCustomPrefetch, useKeepFresh: useCustomKeepFresh, }: Options<Props, PreloadOptions, PrefetchOptions, KeepFreshOptions>): AsyncComponentType<ComponentType<Props>, Props, PreloadOptions, PrefetchOptions, KeepFreshOptions>; export {}; //# sourceMappingURL=component.d.ts.map