UNPKG

@leancodepl/utils

Version:

Common utility functions and React hooks for web applications

26 lines (25 loc) 734 B
/** * React hook for tracking async task execution with loading state. * Automatically manages a loading counter and provides a wrapper function for tasks. * * @returns A tuple containing [isLoading: boolean, runInTask: function] * @example * ```typescript * function MyComponent() { * const [isLoading, runInTask] = useRunInTask(); * * const handleSave = async () => { * await runInTask(async () => { * await saveData(); * }); * }; * * return ( * <button onClick={handleSave} disabled={isLoading}> * {isLoading ? 'Saving...' : 'Save'} * </button> * ); * } * ``` */ export declare function useRunInTask(): readonly [boolean, <T>(task: () => Promise<T> | T) => Promise<T>];