---
title: "Recipe: a long list or grid that loads more"
description: "A long list or grid that loads more: virtualized rows, each holding N cards."
modificationDate: "2026-11-18"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: a long list or grid that loads more

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/long-lists: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

Virtualize rows, each holding N cards (two here). The list has one direct keyed
`for`; its template has one root in normal flow. Loading content follows the
`for` as a fixed child.

```prompt Load more rows as a list scrolls
Make a long list or grid in the Exact app in this folder draw only the rows in view, and load the next page when the person nears its end. Use https://github.com/expo/exact/blob/main/docs/recipes/long-lists.md as the source for each step. The Exact checkout has the same page at docs/recipes/long-lists.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. If I did not say which list, how many cards a row holds (one for a list, more for a grid), and which API gives a page and its next cursor, ask me before you write code. Do not invent a URL.
3. In app.ts, keep the loaded items and the next cursor. The resource's source returns the rows and `hasNext`. A second source (`nextPage` in the recipe) appends a page and returns `{ ok: true }`: append the page before `refreshes` reads the resource again. For a grid, return each row with its cards. Name the API's origin in `grants`.
4. In app.contract, draw a `list` with `virtualized=true`, a `height`, an `estimated-item-height`, and `reachend` that names the action that loads more. Give the list one direct keyed `for`, and give its template one root in normal flow.
5. In that action, send the `mutation` only while `hasNext` is true and neither the resource nor the mutation is `pending`. Draw the loading text (`role="status"`) in an `if` after the `for`, as a child of the list: never inside the keyed rows.
6. Leave `reach-margin` at its default (`"100%"`) unless I ask for an earlier prefetch. To load older rows at the top instead, read the `chat` pattern (docs/patterns/chat/app.contract in the Exact checkout). Do not run `bun exact.mjs pattern chat` in this app without asking me: it writes files.
7. Add a test in app.test.contract that runs `clock data` and expects a card of the first page (`expect tree has`). A first page shorter than two ports loads the next page on first paint: expect the first card of that page too. Answer pages from the network with `answer fetch`, as docs/recipes/tests.md lists it.
8. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 9) and report it; do not keep trying.
9. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
10. Tell me which list changed, the page size and where the pages come from, what the tests and checks reported, and the launch command for each target platform.
```

```contract
shape Product
  id: string
  title: string
shape GridRow
  id: string
  cards: Product[]
shape Catalog
  rows: GridRow[]
  hasNext: bool
shape Reply
  ok: bool

component Shop
  resource catalog = loadCatalog() as shape Catalog else empty()
  mutation more as shape Reply refreshes catalog
  derive loading = pending(catalog) or pending(more)
  action loadMore
    if catalog.hasNext and not loading
      send more = nextPage()
  view
    list id="products" testId="products" virtualized=true appearance="none"
      height="100%" estimated-item-height=124 reachend=loadMore reach-margin="100%"
      for r in catalog.rows key=r.id
        row gap=12 padding=12
          for p in r.cards key=p.id
            column flex=1 min-width=0 min-height=100
              text p.title testId=`product-${p.id}`
      if loading
        text "Loading…" role="status" padding=12 testId="loading"
```

In `app.ts`, append the page before `refreshes` re-reads the resource's answer
([after a write](https://exact.expo.dev/recipes/after-a-write.md)). This fake API has three pages of twenty;
replace `fetchPage` with your API and its next cursor, and name its origin in `grants`:

```ts
import type { Answer, Result, Sources } from './app.contract.d.ts';
export const grants = '';
type Product = Result<'loadCatalog'>['rows'][number]['cards'][number];
let items: Product[] = [];
async function fetchPage(page: number) {
  return { items: Array.from({ length: 20 }, (_, i) => {
    const id = String(page * 20 + i + 1);
    return { id, title: `Product ${id}` };
  }), next: page < 2 ? page + 1 : null };
}
let cursor: number | null = 0;
async function append() {
  if (cursor === null) return;
  const page = await fetchPage(cursor);
  items = items.concat(page.items);
  cursor = page.next;
}
const sources: Sources = {
  loadCatalog: async () => {
    if (cursor === 0) await append();
    return { hasNext: cursor !== null, rows: items.filter((_, i) => i % 2 === 0)
      .map((p, i) => ({ id: p.id, cards: items.slice(i * 2, i * 2 + 2) })) };
  },
  nextPage: async () => { await append(); return { ok: true }; },
};
export const answer: Answer = (source, args, store, storage, native) => sources[source](args, store, storage, native);
```

- The loading child stays mounted while a page is out and is separate from the
  keyed data. It appears after the last row, including when there are no rows.
  `hasNext` stops requests after the last page; the pending guard prevents
  duplicates. A failed mutation leaves the previous answer intact.
- `reach-margin` is a nonnegative px or % of the port (default `"100%"`).
  Increase it to prefetch earlier. Flings extend the lead. A first page
  shorter than two ports loads the next on first paint.
- Page up with `bun exact.mjs pattern chat`. For a [live SQLite window](https://exact.expo.dev/recipes/large-live-list.md), keep both cursors.
