For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/react.uselynxglobaleventlistener.md.
This is the dev preview website. Check out the document at 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'
    />
  )
}