UNPKG

react-exo-hooks

Version:

A collection of useful hooks for data structures and logic, designed for efficiency

23 lines (22 loc) 1.09 kB
export type PromiseResult<T, P extends boolean, E = unknown> = { state: 'waiting'; result: P extends true ? T | undefined : undefined; error: P extends true ? E | undefined : undefined; } | { state: 'resolved'; result: T; error: P extends true ? E | undefined : undefined; } | { state: 'rejected'; result: P extends true ? T | undefined : undefined; error: E; }; /** * A hook that dynamically refetches data on dependency update * @note The first-order function runs on server-side and client-side and determines whether the async second-order function should run client-side * @param fn The async function to run * @param deps The dependencies * @param persist Persist result values and error values into states that wouldn't normally have them * @returns An object containing the state and settled values */ export declare function usePromise<T, P extends boolean, E = unknown>(fn: () => false | undefined | null | '' | ((signal?: AbortSignal) => Promise<T>), deps?: React.DependencyList, persist?: P): PromiseResult<T, P, E>;