MCPcopy
hub / github.com/editablejs/editable / useEvent

Function useEvent

packages/editor/src/hooks/use-event.ts:5–15  ·  view source on GitHub ↗
(type: T, handler: EventHandler<T>)

Source from the content-addressed store, hash-verified

3import { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect'
4
5export const useEvent = <T extends EventType>(type: T, handler: EventHandler<T>) => {
6 const editor = useEditableStatic()
7
8 useIsomorphicLayoutEffect(() => {
9 const event = EventEmitter.get(editor)
10 event.on(type, handler)
11 return () => {
12 event.off(type, handler)
13 }
14 }, [type, handler, editor])
15}

Callers

nothing calls this directly

Calls 4

useEditableStaticFunction · 0.90
getMethod · 0.80
onMethod · 0.80
offMethod · 0.80

Tested by

no test coverage detected