import { useEffect } from "react";
import Taro from "@tarojs/taro";

export const useEventChannel = (
  callback: (eventChannel: Taro.EventChannel) => void
) => {
  useEffect(() => {
    const eventChannel = (
      Taro.getCurrentInstance().page as any
    ).getOpenerEventChannel();
    if (eventChannel) {
      callback(eventChannel);
    }

    // 清理函数
    return () => {
      // 可以在这里移除所有事件监听
    };
  }, [callback]);
};
