MCPcopy Create free account
hub / github.com/msgbyte/tailchat / useSharedEventHandler

Function useSharedEventHandler

client/shared/event/index.ts:94–111  ·  view source on GitHub ↗
(eventName: T, handler: H)

Source from the content-addressed store, hash-verified

92};
93
94export function useSharedEventHandler<
95 T extends SharedEventType,
96 H extends SharedEventMap[T]
97>(eventName: T, handler: H) {
98 const handlerRef = useUpdateRef(handler);
99
100 useEffect(() => {
101 const _handler: SharedEventMap[T] = (...args: any[]) => {
102 (handlerRef.current as any)(...args);
103 };
104
105 sharedEvent.on(eventName, _handler);
106
107 return () => {
108 sharedEvent.off(eventName, _handler);
109 };
110 }, []);
111}

Callers 6

ChatReply.tsxFile · 0.85
index.tsxFile · 0.85
NormalList.tsxFile · 0.85
useGroupPanelExtraBadgeFunction · 0.85

Calls 3

useUpdateRefFunction · 0.90
onMethod · 0.80
offMethod · 0.80

Tested by

no test coverage detected