GlobalProps

lynx.__globalProps is a global variable, which is an object and you can access it from anywhere。

  • It is read-only in the front-end code, you cannot modify its value
  • The client can set and update its value by calling the API provided by lynx SDK
  • Every time the client performs an update, it will trigger a re-rendering of the entire page

Usage

// The properties within the `lynx.__globalProps` object are not managed by Lynx itself. 
// Therefore, you must extend its interface yourself.
declare module '@lynx-js/types' {
  interface GlobalProps {
    appTheme: string;
    title: string;
  }
}

function App() {
  const themeClass = useMemo(
    () => `theme-${lynx.__globalProps.appTheme}`,
    [lynx.__globalProps.appTheme],
  );

  return (
    <view class={themeClass}>
      <text>{lynx.__globalProps.title}</text>
    </view>
  );
}

Client side

__globalProps can be updated through the API provided by LynxView

Android

void updateGlobalProps(@NonNull Map<String, Object> props)

void updateGlobalProps(@NonNull TemplateData props)

iOS

- (void)updateGlobalPropsWithDictionary:(NSDictionary<NSString*, id>*)data

- (void)updateGlobalPropsWithTemplateData:(LynxTemplateData*)data

Compatibility

LCD tables only load in the browser

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.