UNPKG

next-loaders

Version:
14 lines (13 loc) 746 B
import { ActionCallbacks, ActionInferred, LoaderServerAction } from "./types"; export interface CreateActionOptions { debounce?: number; throttle?: number; } export type ActionProgress = 'idle' | 'loading' | 'success' | 'error'; export default function createAction<T, P = never>(action: LoaderServerAction<T, P>, options?: CreateActionOptions): (props?: ActionCallbacks<T>) => readonly [{ execute: ActionInferred<T, P>; cancel: () => void; debounce: (...args: P extends never ? [] : [...P extends any[] ? P : [P], (ActionCallbacks<T> | undefined)?]) => void; throttle: (...args: P extends never ? [] : [...P extends any[] ? P : [P], (ActionCallbacks<T> | undefined)?]) => void; progress: ActionProgress; }, boolean];