UNPKG

@figliolia/react-hooks

Version:

A small collection of simple React Hooks you're probably rewriting on a regular basis

24 lines (23 loc) 507 B
export class AnimationFrame { IDs = new Set(); execute(callback) { const ID = requestAnimationFrame(() => { callback(); }); return () => { this.cancel(ID); }; } abortAll() { for (const ID of this.IDs) { cancelAnimationFrame(ID); } this.IDs.clear(); } cancel(ID) { if (ID && this.IDs.has(ID)) { cancelAnimationFrame(ID); this.IDs.delete(ID); } } }