For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/api/react.uselynxglobaleventlistener.md.
这是开发预览网站。请访问正式文档 lynxjs.org

Home > @lynx-js/react > useLynxGlobalEventListener

useLynxGlobalEventListener() function

useLynxGlobalEventListener helps you addListener as early as possible.

Signature:

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

Parameters

Parameter

Type

Description

eventName

string

Event name to listen

listener

T

Event handler

Returns:

void

Example

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'
    />
  )
}