bippy
Version:
hack into react internals
18 lines (16 loc) • 555 B
text/typescript
export interface Unsubscribe extends Disposable {
(): void;
}
/**
* Wraps a teardown callback so it is both callable and a `Disposable`,
* letting subscriptions compose through explicit resource management:
*
* @example
* ```ts
* using instrumentation = instrument({ onCommitFiberRoot });
* using refresh = instrumentReactRefresh({ onRefresh: handleRefresh });
* // both torn down automatically at scope exit
* ```
*/
export const toUnsubscribe = (dispose: () => void): Unsubscribe =>
Object.assign(dispose, { [Symbol.dispose]: dispose });