nuxt-apex
Version:
Auto-generates fully typed useFetch composables for Nuxt 3/4 server endpoints with Zod validation and zero boilerplate
30 lines (29 loc) • 1.08 kB
TypeScript
import { type Ref, type ShallowRef } from 'vue';
/**
* Status of the load operation, matching useFetch statuses.
*/
export type LoadStatus = 'idle' | 'pending' | 'success' | 'error';
/**
* Options for useLoad when providing an async function.
* @template A - tuple of arguments the async function accepts
*/
export interface UseLoadOptions<A extends any[]> {
/** Auto‑invoke on setup */
immediate?: boolean;
/** Initial args for immediate load */
args?: A;
}
/**
* Return value from useLoad.
* @template T - return type of the async operation
* @template A - tuple of arguments for the load trigger
*/
export interface UseLoadReturn<T, A extends any[]> {
status: Ref<LoadStatus>;
data: ShallowRef<T | null>;
error: ShallowRef<unknown>;
/** Trigger the async operation again */
load: (...args: A) => Promise<void>;
}
export declare function useLoad<T>(promise: Promise<T>): UseLoadReturn<T, []>;
export declare function useLoad<T, A extends any[]>(asyncFn: (...args: A) => Promise<T>, options?: UseLoadOptions<A>): UseLoadReturn<T, A>;