Lynx ui lazy component

From lynx-family/lynx-ui · View interactive version

Lynx ui lazy component is an AI agent skill from the GitHub repository lynx-family/lynx-ui. Provide the information about the `<LazyComponent>`. Show the common use cases, basic usage, and critical development Advises.

How to use this skill

Skill file

lynx-ui-lazy-component SKILL

<LazyComponent> is a component that lazy loads the content when it is visible in the viewport.

1. Common Use Cases

2. Basic Usage

<LazyComponent> is used to display the content of the page only when it is visible in the viewport.

import { LazyComponent } from '@lynx-js/lynx-ui'

function App() {
  return (
    <view>
      <LazyComponent
        scene={'scene'}
        pid={'pid'}
        estimatedStyle={{ width: '1px', height: '1px' }}
      >
        <RealItem />
      </LazyComponent>
    </view>
  )
}

3. Example for build Virtualized-List

You can build a virtualized list by embedding <LazyComponent> in the slot of <ScrollView>.

import { LazyComponent } from '@lynx-js/lynx-ui'
import { ScrollView } from '@lynx-js/lynx-ui'

function App() {
  return (
    <ScrollView
      scrollOrientation='vertical'
      lazyOptions={{ enableLazy: false }}
      style={{ width: '100%', height: '400px' }}
    >
      {
        // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
        [...Array(20)]
          .map((_, index) => index)
          .map((_item, index) => (
            <LazyComponent
              key={index}
              scene={'scene'}
              pid={`pid_${index}`}
              estimatedStyle={{ width: '100%', height: '100px' }} // make sure the estimated size is equal to the real size
              unmountOnExit
            >
              <view
                style={{
                  width: '100%',
                  height: `${300 + index * 10}px`,
                  padding: '5px',
                  border: '50px red',
                }}
              >
                <text>item</text>;
              </view>
            </LazyComponent>
          ))
      }
    </ScrollView>
  )
}

4. Example for adjust exposure-margin

You can adjust the exposure margin of <LazyComponent> by setting the bottom, top, left, and right props. So that the content of the item is loaded earlier than it is visible in the viewport.

import { LazyComponent } from '@lynx-js/lynx-ui'

function App() {
  return (
    <view>
      <LazyComponent
        scene={'scene'}
        pid={'pid'}
        bottom='200px'
        top='200px'
        left='200px'
        right='200px'
        estimatedStyle={{ width: '1px', height: '1px' }}
      >
        <RealItem />
      </LazyComponent>
    </view>
  )
}

5. Critical Development Advises

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.