preact-missing-hooks
Version:
A lightweight, extendable collection of missing React-like hooks for Preact — plus fresh, powerful new ones designed specifically for modern Preact apps.
11 lines (10 loc) • 415 B
TypeScript
type EventMap = Record<string, (...args: any[]) => void>;
/**
* A Preact hook to publish and subscribe to custom events across components.
* @returns An object with `emit` and `on` methods.
*/
export declare function useEventBus<T extends EventMap>(): {
emit: <K extends keyof T>(event: K, ...args: Parameters<T[K]>) => void;
on: <K extends keyof T>(event: K, handler: T[K]) => () => void;
};
export {};