For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt, and this page is available as Markdown at /next/zh/api/react/Hooks/useLynxGlobalEventListener.md.
  • 简体中文
  • 函数: useLynxGlobalEventListener()

    useLynxGlobalEventListener<T extends (...args: any[]) => void>(eventName: string, listener: T): void

    useLynxGlobalEventListener 帮助你尽早地 addListener。

    类型参数

    类型参数
    T extends (...args: any[]) => void

    参数

    参数类型描述
    eventNamestring要监听的事件名
    listenerT事件处理函数

    返回

    void

    示例

    使用此 Hook 监听 'exposure' 事件和 'disexposure' 事件

    function App() {
      useLynxGlobalEventListener('exposure', (e) => {
        console.log("exposure", e)
      })
      useLynxGlobalEventListener('disexposure', (e) => {
        console.log("disexposure", e)
      })
      return (
        <view
          style='width: 100px; height: 100px; background-color: red;'
          exposure-id='a'
        />
      )
    }
    除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。