import { useEffect } from "react";
import { useKeypressContext } from "../contexts/KeypressContext.js";
function useKeypress(onKeypress, { isActive }) {
  const { subscribe, unsubscribe } = useKeypressContext();
  useEffect(() => {
    if (!isActive) {
      return;
    }
    subscribe(onKeypress);
    return () => {
      unsubscribe(onKeypress);
    };
  }, [isActive, onKeypress, subscribe, unsubscribe]);
}
export {
  useKeypress
};
