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

    接口: Lynx

    APIs under lynx global variable that added by ReactLynx.

    示例

    lynx.registerDataProcessors(...);
    lynx.querySelector(...);
    lynx.querySelectorAll(...);

    属性

    registerDataProcessors()

    registerDataProcessors: (dataProcessorDefinition?: DataProcessorDefinition) => void;

    Register DataProcessors. You MUST call this before root.render().

    参数

    范围类型
    dataProcessorDefinition?DataProcessorDefinition

    返回

    void

    Examples

    You MUST call lynx.registerDataProcessors before calling root.render().

    import { root } from "@lynx-js/react"
    
    // You MUST call this before `root.render()`
    lynx.registerDataProcessors({
      defaultDataProcessor: () => {...} // default DataProcessor
      dataProcessors: {
        getScreenMetricsOverride: () => {...} // named DataProcessor
      }
    })
    
    root.render(<App/>);

    If you have a class component with static defaultDataProcessor or static dataProcessors, you can use it to register DataProcessors.

    import { root, Component } from "@lynx-js/react"
    
    class App extends Component {
      static defaultDataProcessor() {
         ...
      }
    
      static dataProcessors = {
        getScreenMetricsOverride() {
          ...
        }
      }
    }
    
    lynx.registerDataProcessors(App); // You can pass `App` because it has the required shape
    root.render(<App/>);

    For developers who want fully typed defaultDataProcessor, they can achieve it by extends interface InitDataRaw and InitData.

    import { root } from "@lynx-js/react"
    
    interface ExistingInterface {
      somePropertyFromExistingInterface: number
    }
    
    declare module '@lynx-js/react' {
      interface InitDataRaw extends ExistingInterface {
        someAnotherCustomProperty: string
      }
    }
    
    lynx.registerDataProcessors({
      defaultDataProcessor: (initDataRaw) => {
        initDataRaw.somePropertyFromExistingInterface // will be typed
      }
    })
    

    For developers who want fully typed defaultDataProcessor, they can achieve it by extends interface InitDataRaw and InitData.

    import { root, useInitData } from "@lynx-js/react"
    
    interface AnotherExistingInterface {
      someAnotherPropertyFromExistingInterface: number
    }
    
    declare module '@lynx-js/react' {
      interface InitData extends AnotherExistingInterface {
        someCustomProperty: string
      }
    }
    
    root.registerDataProcessors({
      defaultDataProcessor: () => {
        return {
          someCustomProperty: 'value', // will be typed
          someAnotherPropertyFromExistingInterface: 1, // will be typed
        }
      }
    })
    
    function App() {
      const initData = useInitData();
    
      initData.someCustomProperty // will be typed
      initData.someAnotherPropertyFromExistingInterface // will be typed
    }
    

    定义于

    @lynx-js/react/runtime/lib/lynx-api.d.ts:454


    triggerGlobalEventFromLepus()

    triggerGlobalEventFromLepus: (eventName: string, params: any) => void;

    An alias of lynx.getJSModule("GlobalEventEmitter").trigger(eventName, params) only in Lepus

    参数

    范围类型
    eventNamestring
    paramsany

    返回

    void

    定义于

    @lynx-js/react/runtime/lib/lynx-api.d.ts:345

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