BakeNative is under active development. APIs may change.
Skip to Content
BakeNative

Long lists

Render a fixed-height column with List in React or VirtualList in Octane, on web and native.

Both adapters can render just the rows in and around the visible part of a long list. Rows scroll with the page.

React List

Import List from @bake-native/react for a single column of equal-height rows. Pass the data to data and the row component to renderItem({ item, index }). Set itemHeight to a positive constant in logical pixels and give each row that height.

import { useState } from 'react';
import { List, Pressable, Text } from '@bake-native/react';

type Match = { id: string; name: string };
const HEIGHT = 48;

export function Matches({ rows }: { rows: Match[] }) {
  const [selectedId, setSelectedId] = useState<string | null>(null);
  return (
    <List
      data={rows}
      itemHeight={HEIGHT}
      keyExtractor={row => row.id}
      recycleItems
      renderItem={({ item }) => (
        <Pressable
          style={{ height: HEIGHT }}
          accessibilityRole="button"
          onPress={() => setSelectedId(item.id)}
        >
          <Text>{item.name}{item.id === selectedId ? ' (selected)' : ''}</Text>
        </Pressable>
      )}
    />
  );
}

By default, recycleItems is false. The outer slot is reused, and its row component remounts when it receives a different item key. Set recycleItems to reuse compatible row components and views as well. Local state and refs then stay with the slot as it moves between items. The example stores the selection in the parent by match ID, so it follows the match through scrolling and reordering. Use the same approach for an editable draft that belongs to an item.

Legend List uses the same opt-in convention for recycleItems. Its optional estimatedItemSize helps allocate the initial window. BakeNative requires the actual fixed itemHeight to position every row. Legend List API reference

Use initialCount for the slot count before the viewport is known (default 24), overscan for the distance beyond the viewport (default 1 viewport) and className for the container. Horizontal, multi-column, variable-height and independently scrolling nested lists require a different layout.

Octane VirtualList

Octane exports VirtualList from @bake-native/octane. It takes an explicit itemHeight and calls renderItem(item, index).

import { VirtualList } from '@bake-native/octane';

<VirtualList
  items={coins}
  itemHeight={64}
  renderItem={(coin) => <CoinRow coin={coin} />}
/>
PropMeaning
itemsThe array to show
itemHeightEvery row's height in px (rows are positioned from it)
renderItem(item, index)The row
overscanHow far beyond the visible part to render, in viewports (default 1)
initialCountSlots rendered before the first scroll position is known (default 24)
classClass of the list container

How it works

  • The list is one container as tall as all its rows. Rows are absolutely positioned at index × itemHeight.
  • It follows the page scroll: on the web through window scroll events, on native through the host's scroll view (host.on('scroll')) and the container's position (onLayout). Native scroll positions are coalesced: while JavaScript handles one, only the latest waits.
  • Rows live in fixed slots (index % pool). Scrolling rebinds a slot to another item, so the host sees prop updates, not new or moved elements, and a scroll step lays out only the rebound rows.
  • On native the host recycles the slots itself: in the same frame as the scroll, before JavaScript answers, it moves every slot to the row it is about to show (the same formula the list uses), and the next commit only fills in the content. A fast fling never shows a blank gap; if JavaScript falls behind by more than the overscan, a row briefly shows the item its slot had before.

The following measurements used the Octane adapter. On an Apple M4, a 5,000-row list scrolled at 24,000 pt/s (200 pt per 120 Hz frame) costs about 1 ms of JavaScript and 1 ms of native work per step, with about 240 host elements mounted. On Windows, a 10,000-row list (48 px rows, 900 px viewport) flung end to end at the same speed shows no blank row, keeps 180 views (59 slots) whatever its length, places its slots in under 1 µs per scroll tick, and lays out a JavaScript answer in about 0.5 ms (p99 0.6 ms) in the core and the host's tree. See Runtime performance.

The window math (first, last, pool, the row each slot shows) is one formula, in packages/core/virtual-window.js and in the Rust core (bake_core::virtual_list), pinned to each other by shared test vectors.

Supported in v0.1

VirtualList v0.1 is one column of rows of one fixed height that scrolls with the page. A native build (bake build) fails with an error for anything else, instead of drawing it wrongly:

ErrorWhenInstead
list-variable-heightitemHeight is a function, not a number known at build time (a literal, a const, or arithmetic on them), or not positive; estimatedItemHeight, getItemHeight, itemSizeRows of one height
list-nested-scrollThe list is inside an element with overflow: auto or scroll (checked on the first screen)Put the list in the page scroll
list-gridnumColumns, columns, horizontal; the list's class makes it a grid or a wrapping flex box (checked on the first screen)One row per item; put several items in one row component
list-prop-unknownAny other prop, such as stickyHeaderIndicesOnly the props above

At run time, on every target, an itemHeight that is not a positive number throws. Variable heights, lists in inner scroll containers, grids, horizontal lists and sticky section headers are not supported yet. As with every build error, // bake-allow <id> on the line allows one finding.

Rules

  • Rows must be itemHeight tall.
  • Octane keeps row state on the reused slot. Store persistent per-item state by item ID outside the row.
  • Updating one item: change the data and re-render; only the visible slots render again.

On this page