UNPKG

@supunlakmal/hooks

Version:

A collection of reusable React hooks

29 lines (28 loc) 1.05 kB
type RequestIdleCallbackHandle = number; type RequestIdleCallbackOptions = { timeout?: number; }; type RequestIdleCallbackDeadline = { readonly didTimeout: boolean; timeRemaining: () => number; }; declare global { interface Window { requestIdleCallback: (callback: (deadline: RequestIdleCallbackDeadline) => void, opts?: RequestIdleCallbackOptions) => RequestIdleCallbackHandle; cancelIdleCallback: (handle: RequestIdleCallbackHandle) => void; } } /** * Hook to schedule a function execution during browser idle periods. * Uses `requestIdleCallback` API. * * @param callback The function to execute when the browser is idle. * @param options Optional configuration, primarily the `timeout`. * @returns A tuple containing functions to `start` and `cancel` the scheduled callback. */ export declare function useIdleCallback(callback: (deadline: RequestIdleCallbackDeadline) => void, options?: RequestIdleCallbackOptions): { start: () => void; cancel: () => void; isActive: boolean; }; export {};