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/Function.useLynxGlobalEventListener.md.
  • 简体中文
  • @lynx-js/react / useLynxGlobalEventListener

    函数: useLynxGlobalEventListener()

    function useLynxGlobalEventListener<T>(eventName: string, listener: T): void

    useLynxGlobalEventListener helps you addListener as early as possible.

    类型参数

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

    参数

    范围类型描述
    eventNamestringEvent name to listen
    listenerTEvent handler

    返回

    void

    示例

    Use this hooks to listen to event 'exposure' and event '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'
        />
      )
    }

    定义于

    @lynx-js/react/runtime/lib/core/hooks/useLynxGlobalEventListener.d.ts:29

    除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。