import { DependencyList , useEffect } from 'react' ; import { emitter , EmitterTypes } from '../libs/emitter' ; export function useEmitter < K extends keyof EmitterTypes > ( key , callback , deps = [ ] ) { useEffect ( ( ) => { if ( ! ( key && callback ) ) return ; const listener = emitter . addListener ( key , callback ) ; return ( ) => listener . remove ( ) ; } , [ key , ... deps ] ) ; return emitter ; }