UNPKG

@supunlakmal/hooks

Version:

A collection of reusable React hooks

23 lines (22 loc) 931 B
type AnimationCallback = (progress: number, elapsed: number) => void; interface UseAnimationOptions { duration: number; onComplete?: () => void; } interface UseAnimationControls { start: () => void; stop: () => void; reset: () => void; isRunning: boolean; } /** * Custom hook to manage a basic animation loop using requestAnimationFrame. * * @param callback - Function called on each animation frame. Receives progress (0-1) and elapsed time (ms). * @param options - Configuration object. * @param options.duration - Total duration of the animation in milliseconds. * @param options.onComplete - Optional callback triggered when the animation completes its duration. * @returns Controls object with start, stop, reset functions and running status. */ export declare const useAnimation: (callback: AnimationCallback, { duration, onComplete }: UseAnimationOptions) => UseAnimationControls; export {};