@thibault.sh/hooks
Version:
A comprehensive collection of React hooks for browser storage, UI interactions, and more
17 lines (15 loc) • 485 B
TypeScript
interface AsyncState<T> {
isLoading: boolean;
error: Error | null;
value: T | null;
}
/**
* Hook that handles async operations with loading and error states
* @param asyncFunction - Async function to execute
* @returns Object containing execute function, loading state, error, and value
*/
declare function useAsync<T>(asyncFunction: (...args: any[]) => Promise<T>): {
execute: (...args: any[]) => Promise<void>;
status: AsyncState<T>;
};
export { useAsync };