---
title: "Recipe: rows added and removed while editing"
description: "Rows added and removed while editing: each row's remove is a red minus-circle and a swipe; Add is the section's last row."
modificationDate: "2026-11-12"
---

> ## 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: rows added and removed while editing

<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/editable-rows: <what was wrong or missing>"`

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

</AgentInstructions>

A poll's options, a recipe's steps: each row's remove is a red `minus-circle`
(`destructive=true`), shown while a row may go, and its swipe (`delete=`); Add is the section's
last row. Removing a row asks nothing; the form's Save or Cancel is the commitment.

```prompt Let a person add and remove rows
Let a person add and remove rows in a list of the Exact app in this folder while they edit it, such as a poll's options or a recipe's steps. Use https://github.com/expo/exact/blob/main/docs/recipes/editable-rows.md as the source for each step. The Exact checkout has the same page at docs/recipes/editable-rows.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, propose one from the app's data, with its fewest and most rows, and ask me before you write code.
3. In app.contract, draw the rows in a `section` of an inset-grouped `list`, with an `add` action, a `remove(i)` action and an `edit(i, v)` action. Give each row a red remove button (`destructive=true`, `symbol:minus-circle`, an `aria-label` that names the row) and its swipe (`delete=remove(i)`). Show the remove button and allow the swipe only while the list has more than its fewest rows.
4. Make Add the section's last row, and show it only while the list has fewer than its most rows.
5. A removed row asks nothing: the form's Save or Cancel is the commitment. If the form saves something that cannot be undone once saved, it asks first (`bun exact.mjs contract vocab confirm`).
6. Add a test in app.test.contract that adds a row, types in it, removes another, expects the values that stay, and expects no remove button at the fewest rows.
7. 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 8) and report it; do not keep trying.
8. 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.
9. Tell me which list can change and its limits, what the tests and verify reported, and the launch command for each target platform.
```

```contract
shape Choice
  id: number
  text: string

component Options
  state options: Choice[] = [Choice(id=0, text=""), Choice(id=1, text="")]
  state nextId = 2
  action edit(id: number, v: string)
    options = options.map(o => o.id == id ? Choice(o, text=v) : o)
  action add
    options = options.concat([Choice(id=nextId, text="")])
    nextId = nextId + 1
  action remove(id: number)
    options = options.filter(o => o.id != id)
  view
    list appearance="auto" listStyle="inset-grouped" height="100%"
      section
        header
          text "Options"
        for o, i in options key=o.id
          row gap=8 align-items="center" delete=remove(o.id) disabled=(options.length <= 2)
            if options.length > 2
              button press=remove(o.id) destructive=true aria-label=`Remove option ${i + 1}` testId=`remove-${i}`
                image "symbol:minus-circle"
            input value=o.text input=edit(o.id) placeholder=`Option ${i + 1}` aria-label=`Option ${i + 1}`
              testId=`option-${i}` flex=1 min-width=0
        if options.length < 6
          button press=add testId="add-option"
            text "Add Option"
```

```contract-test
test "an option is added and removed, never below two"
  expect tree missing "remove-0"
  tap "add-option"
  type "option-2" "Tacos"
  tap "remove-0"
  expect state options.1.text == "Tacos"
  expect tree missing "option-2"
  expect tree missing "remove-0"
```

- Each row is keyed by an id it keeps (`nextId`), not its position, so a field's text and focus
  stay with their row when a row above it goes (`lower-key-position`).
- What can't be undone once saved (Delete, Close Poll, Cancel Event) asks first (`contract vocab
  confirm`).
