SwiftUI.js
Components

LazyHGrid

LazyHGrid is a container that arranges its children in a horizontal grid, loading them lazily. LazyHGrid creates a horizontal grid layout with lazy loading for performance.

LazyHGrid is a container that arranges its children in a horizontal grid, loading them lazily. LazyHGrid creates a horizontal grid layout with lazy loading for performance.

Examples

Basic Usage

Preview unavailable for this example in the static docs build.

Show code
<LazyHGrid rows={2} spacing={10}>{items.map(item => (
      <Card key={item.id}>
        <VStack spacing={5} style={{ padding: '15px' }}>
          <Text style={{ fontWeight: 'bold' }}>{item.name}</Text>
        </VStack>
      </Card>
    ))}</LazyHGrid>

Three Rows

Preview unavailable for this example in the static docs build.

Show code
<LazyHGrid rows={3} spacing={15}>{items.map(item => (
      <Card key={item.id}>
        <VStack spacing={5} style={{ padding: '20px' }}>
          <Text style={{ fontWeight: 'bold' }}>{item.name}</Text>
        </VStack>
      </Card>
    ))}</LazyHGrid>

Four Rows

Preview unavailable for this example in the static docs build.

Show code
<LazyHGrid rows={4} spacing={10}>{items.map(item => (
      <Card key={item.id}>
        <VStack spacing={5} style={{ padding: '15px' }}>
          <Text style={{ fontWeight: 'bold' }}>{item.name}</Text>
        </VStack>
      </Card>
    ))}</LazyHGrid>

With Images

Preview unavailable for this example in the static docs build.

Show code
<LazyHGrid rows={2} spacing={10}>
      {items.map(item => (
        <Card key={item.id}>
          <VStack spacing={5}>
            <div style={{ width: '100px', height: '100px', backgroundColor: '#e0e0e0', borderRadius: '4px' }} />
            <Text style={{ padding: '10px', fontWeight: 'bold' }}>{item.name}</Text>
          </VStack>
        </Card>
      ))}
    </LazyHGrid>

Large Grid

Preview unavailable for this example in the static docs build.

Show code
<LazyHGrid rows={3} spacing={10}>
        {largeItems.map(item => (
          <Card key={item.id}>
            <VStack spacing={5} style={{ padding: '15px' }}>
              <Text style={{ fontWeight: 'bold' }}>{item.name}</Text>
            </VStack>
          </Card>
        ))}
      </LazyHGrid>

API

PropTypeRequiredDescription
rowsnumberNoNumber of rows in the grid. Default: 2
spacingnumberNoSpacing between grid items. Default: 0

Inherits additional props from IBaseComponent.

Overview

LazyHGrid is a container that arranges its children in a horizontal grid, loading them lazily. LazyHGrid creates a horizontal grid layout with lazy loading for performance.

SwiftUI Correspondence: Similar to SwiftUI's LazyHGrid.

Notes

  • LazyHGrid requires a rows prop to specify the number of rows
  • LazyHGrid supports spacing prop for item spacing
  • LazyHGrid only renders visible items for better performance
  • LazyHGrid is ideal for horizontal grid layouts with many items
  • Default rows is 2 if not specified

Best Practices

  1. Rows: Choose appropriate number of rows for your layout
  2. Spacing: Use consistent spacing between grid items
  3. Performance: LazyHGrid improves performance for large grids
  4. Keys: Always provide unique keys for grid items
  5. Responsive: Consider responsive row counts for different screen sizes

On this page