(
onKeypress: KeypressHandler,
{ isActive }: { isActive: boolean },
)
| 22 | * @param options.isActive - Whether the hook should be actively listening for input. |
| 23 | */ |
| 24 | export function useKeypress( |
| 25 | onKeypress: KeypressHandler, |
| 26 | { isActive }: { isActive: boolean }, |
| 27 | ) { |
| 28 | const { subscribe, unsubscribe } = useKeypressContext(); |
| 29 | |
| 30 | useEffect(() => { |
| 31 | if (!isActive) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | subscribe(onKeypress); |
| 36 | return () => { |
| 37 | unsubscribe(onKeypress); |
| 38 | }; |
| 39 | }, [isActive, onKeypress, subscribe, unsubscribe]); |
| 40 | } |
no test coverage detected