react / useLynxGlobalEventListener

Function: useLynxGlobalEventListener()

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

useLynxGlobalEventListener help you addListener as early as possible.

Type Parameters

Type Parameter
T extends (...args: unknown[]) => 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'
    />
  )
}

Defined in

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

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.