import { onBeforeUnmount } from "vue";

export const useEvent = (eventName, callback) => {
  window.addEventListener(eventName, callback);

  onBeforeUnmount(() => {
    window.removeEventListener(eventName, callback);
  });
};

export const useKeyEvent = (key, callback) => {
  const handler = (e) => {
    console.log("🚀 ~ handler ~ e:", e.key);
    if (e.key === key) {
      callback(e);
    }
  };
  useEvent("keyup", handler);
};
