UNPKG

@base-ui/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

26 lines (25 loc) 550 B
/** * A utility class to manage multiple timeouts. */ export class TimeoutManager { ids = new Map(); start = (key, delay, fn) => { this.clear(key); const id = setTimeout(() => { this.ids.delete(key); fn(); }, delay); /* Node.js types are enabled in development */ this.ids.set(key, id); }; clear = key => { const id = this.ids.get(key); if (id != null) { clearTimeout(id); this.ids.delete(key); } }; clearAll = () => { this.ids.forEach(clearTimeout); this.ids.clear(); }; }