API reference@evolu/commonTypes › CallbackWithTeardown

type CallbackWithTeardown<T> = (value: T) => void | (() => void);

Defined in: packages/common/src/Types.ts:38

A function that receives a value and optionally returns a teardown function.

Use for subscriptions or callbacks that need abort-time teardown.

Example

const subscribe: CallbackWithTeardown<EventSource> = (source) => {
  source.start();
  return () => source.stop();
};