import { useEffect } from "react"
import type { Events } from "webextension-polyfill"

export function useChromeEvent<T extends (...args: any[]) => any>(
  event: Events.Event<T>,
  fn: T,
) {
  useEffect(() => {
    event.addListener(fn)
    return () => event.removeListener(fn)
  }, [event, fn])
}
