/** * An async function that returns data. */ export type AsyncFunction, Output> = (...args: Input) => Promise; /** * A type-safe configuration object for multiple loaders. * * The key is used to cache the result of the loader. * The value is a loader that takes an array of arguments and returns a promise. */ export interface AsyncCacheConfig { [K: string]: AsyncFunction, any> | [AsyncFunction, any>, ...Array]; } /** * A hook that returns, and caches, the results of calling one or more async functions, * typically to load data from a third party via server functions. * * The component it is used in will suspend until ALL async functions have resolved. * * @example * * // load-widgets.server.ts * export default async function loadWidgets() : Promise> { * // fetch widgets from somewhere * } * // load-sprockets.server.ts * export default async function loadSprockets( * material: Material, * max?: number * ): Promise> { * // fetch sprockets from somewhere * } * * // component.tsx * import {useAsyncCache} from "attio/client" * * import loadWidgets from "./load-widgets.server.ts.js" * import loadSprockets from "./load-sprockets.server.ts.js" * * // ... * * // In component: * * const results = useAsyncCache({ * // `loadWidgets` takes zero parameters and can thus be called without an array * widgets: loadWidgets, * // `loadSprockets` takes a `material` parameter, so we call it like this * ironSprockets: [loadSprockets, "iron"], * copperSprockets: [loadSprockets, "copper", 42], * }) * * const {widgets, ironSprockets, copperSprockets} = results.values * * // ... * * // Inside an event handler, perhaps, to refetch *only* the iron sprockets * results.invalidate("ironSprockets") */ export declare function useAsyncCache(config: Config): { values: { [K in keyof Config]: Config[K] extends AsyncFunction ? Output : Config[K] extends [AsyncFunction, ...infer Args] ? Args extends Input ? Output : never : never; }; invalidate: (name: Extract) => void; }; //# sourceMappingURL=use-async-cache.d.ts.map