0.1.1 • Published 1 year ago
@-ft/disposer v0.1.1
Util - Disposer
compose multiple disposables easily into single disposable
Usage
function SomeEffect() {
useEffect(() => {
const timeout = setInterval(() => console.log('Hello world!'), 1000);
const handler = (e) => e.stopPropagation();
document.body.addEventListener('click', handler, true);
return new Disposer()
.add(() => clearInterval(timeout))
.add(() => document.removeEventListener('click', handler, true))
.disposable();
}, []);
return null;
}