Skip to content

Show a list

A Stack or Grid can repeat its children once for each row of a list. Its children are the template: they are designed once and rendered once per row. A Button in the template can act on its row, an Input can edit a field of a local list’s row, a local list’s rows are added and removed with addRow and removeRow, and a host collection’s rows are created, updated and deleted through the host. The order history example uses both kinds of list described here.

A repeated container carries repeat with a literal state path and a row key:

{
"steps": {
"type": "Grid",
"props": {
"columns": 3,
"gap": "md",
"padding": "none",
"minCellWidth": 180
},
"children": [
"step"
],
"repeat": {
"statePath": "/deliverySteps",
"key": "code"
}
}
}

The list is one of two things:

  • A declared host collection. A business object declared with cardinality: "many" is a list of records the host fetches, projected at /objects/{alias}/data. Its key is always the declaration’s identity. A collection may enable create, update and delete besides fetch; see Edit a host row.
  • A local list in document state, such as /deliverySteps above. Its key is a row field you pick, and it should be stable and unique: a row whose key is missing, or repeats another row’s, is skipped.

Anything at the path that is not a list renders nothing. The path is literal — a repeat never reads its list from a row — so one repeat cannot sit inside another’s template.

A collection is declared like any business object, with an array of records as its design sample:

{
"orders": {
"type": "shop.order",
"cardinality": "many",
"identity": "id",
"fields": {
"id": {
"kind": "string",
"required": true
},
"reference": {
"kind": "string",
"required": true
},
"placedOn": {
"kind": "string",
"required": true
},
"status": {
"kind": "string",
"required": true,
"enum": [
"processing",
"shipped",
"delivered"
]
},
"total": {
"kind": "number",
"required": true
},
"note": {
"kind": "string",
"nullable": true
}
},
"capabilities": {
"fetch": {
"inputs": {
"customerId": {
"kind": "string",
"required": true
}
}
},
"update": {
"inputs": {
"note": {
"kind": "string",
"nullable": true,
"maxLength": 120
}
}
},
"delete": {}
},
"sample": [
{
"id": "ord_sample_1",
"reference": "SO-0001",
"placedOn": "2 Sep 2026",
"status": "shipped",
"total": 120,
"note": "Leave with the neighbour"
},
{
"id": "ord_sample_2",
"reference": "SO-0002",
"placedOn": "28 Aug 2026",
"status": "delivered",
"total": 80
}
]
}
}

The host’s fetch answers with the whole list. Every row must carry each required declared field with the right kind and its identity, and no two rows may share one; anything else is a host-contract error on the fetch’s error path, and the last good list stays. Fields a row carries that are not declared are dropped and never reach state.

Inside the template, a Text or Heading content can read the current row:

  • { "$item": "reference" } reads a field of the row. A nested field is /-joined, like address/city. Over a collection, every field read must be declared.
  • { "$index": true } is the row’s position, counting from 0.
{
"order-reference": {
"type": "Heading",
"props": {
"content": {
"$item": "reference"
},
"level": "3",
"align": "left",
"accent": false
},
"children": []
},
"step-number": {
"type": "Text",
"props": {
"content": {
"$index": true
},
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": []
}
}

A Show when condition inside the template can test a row field with $item, so a single row can hide a component; $index is for display only. Here a delivered order shows no status line:

{
"order-status": {
"type": "Text",
"props": {
"content": {
"$item": "status"
},
"size": "md",
"tone": "default",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$item": "status",
"neq": "delivered"
}
}
}

Outside a template both reads are refused.

A Button’s press or a form control’s commit inside the template runs its actions for the row it sits in. Each is the usual list of up to eight actions, checked the same way as anywhere else, and each action can read that row’s fields with $item in two places:

  • A setState record. setState’s value may be a record: a plain object whose values are text, numbers, true/false, null, a $state read, a row field, or another record. This copies the row into ordinary state, to show which row was picked or to start a draft.
  • An object input. An input’s whole value may be a row field, such as { "personId": { "$item": "id" } }, to fetch a detail record for the row that was pressed.

Each order card’s Track this order copies its order’s reference and status into /tracking, which a Stack after the list shows:

{
"order-track": {
"type": "Button",
"props": {
"label": "Track this order",
"variant": "outline",
"size": "sm",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": {
"action": "setState",
"params": {
"statePath": "/tracking",
"value": {
"reference": {
"$item": "reference"
},
"status": {
"$item": "status"
}
}
}
}
}
},
"tracking": {
"type": "Stack",
"props": {
"direction": "horizontal",
"gap": "sm",
"align": "center",
"justify": "start",
"wrap": true,
"padding": "md",
"surface": "soft"
},
"children": [
"tracking-label",
"tracking-reference",
"tracking-status"
],
"visible": {
"$state": "/tracking/reference"
}
}
}

The value is the row’s value as it stands when the event fires, including the value a control’s commit just wrote to that row. A row field is never a param of its own: json-render reads { "value": { "$item": "id" } } as the row’s position in the list, not its value, and the position names another row as soon as rows move, so import refuses it:

Element “order-track” (on.press[0]): setState params.value is a row read, which json-render resolves to the row's position path, not its value; put the row field inside a setState record, an object input or an object action's row.

$index is for display only and never reaches an action, and row reads stay refused outside a template and in lifecycle.startup, which has no row. A record is bounded: up to 4 levels of nesting, 32 fields per level and 64 values in all, with no lists. A row Button cannot write a field of its own row; edit a local row’s fields with a form control instead.

A fetch from a row’s event follows the usual latest-wins rule: when a person presses a row’s Button and then another row’s before the first fetch answers, the first fetch is superseded, its answer dropped and the rest of its actions skipped.

Inside the template of a local list, the value of a form control (a DateRange’s start and end) can edit a field of its own row with $bindItem — a Toggle bound to a row’s done field ticks that row off. Each row’s control edits that row:

{
"todo-list": {
"type": "Stack",
"props": { "direction": "vertical", "gap": "sm", "align": "stretch", "justify": "start", "wrap": false, "padding": "none", "surface": null },
"children": ["todo-title"],
"repeat": { "statePath": "/todos", "key": "id" }
},
"todo-title": {
"type": "Input",
"props": { "label": "Title", "placeholder": "", "inputType": "text", "required": false, "helpText": null, "value": { "$bindItem": "title" } },
"children": []
}
}

The field must be one named field of the row. Import refuses:

  • the whole row ("") or a position such as tags/0;
  • the row key of any repeat over the list — editing it would rebuild the row on every keystroke;
  • a field that holds another field anything in the document reads from the same list’s rows, such as address while another element reads address/city;
  • a row of a declared collection. Host rows are never edited in place: copy the row into a draft with a row Button, edit the draft, and save it with update.
Element “order-note” (props.value): Rows of object “orders” belong to the host and are never edited in place; copy the row into a draft from a button in the row, and save it with update.

A field that holds a record or a list shows its value read-only.

A local list’s rows are added with addRow and removed with removeRow. Both name the list with a literal statePath, which a repeat in the document must render; the repeat’s key is the list’s key, and every repeat over the list must use the same one.

A draft Input outside the list, an Add Button that adds the draft as a row and then clears it, and in each row an Input for a field and a Remove Button:

{
"todo-list": {
"type": "Stack",
"props": { "direction": "vertical", "gap": "sm", "align": "stretch", "justify": "start", "wrap": false, "padding": "none", "surface": null },
"children": ["todo-title", "todo-remove"],
"repeat": { "statePath": "/todos", "key": "id" }
},
"todo-title": {
"type": "Input",
"props": { "label": "Title", "placeholder": "", "inputType": "text", "required": false, "helpText": null, "value": { "$bindItem": "title" } },
"children": []
},
"todo-remove": {
"type": "Button",
"props": { "label": "Remove", "variant": "outline", "size": "sm", "disabled": false, "fullWidth": false },
"children": [],
"on": { "press": { "action": "removeRow", "params": { "statePath": "/todos", "row": { "id": { "$item": "id" } } } } }
},
"new-todo": {
"type": "Input",
"props": { "label": "New todo", "placeholder": "", "inputType": "text", "required": false, "helpText": null, "value": { "$bindState": "/drafts/todo/title" } },
"children": []
},
"add-todo": {
"type": "Button",
"props": { "label": "Add", "variant": "solid", "size": "md", "disabled": false, "fullWidth": false },
"children": [],
"on": {
"press": [
{ "action": "addRow", "params": { "statePath": "/todos", "value": { "title": { "$state": "/drafts/todo/title" }, "done": false } } },
{ "action": "setState", "params": { "statePath": "/drafts/todo", "value": {} } }
]
}
}
}
  • addRow’s value is a record, as for setState, holding the new row’s fields. It may not set the key: Mica gives every added row a key of its own, row-1, row-2 and so on, skipping any key the list already holds, so an added row never collides with another. The row joins the end of the list.
  • removeRow’s row names the row by its key: { "id": … }, whose value is text or a number, a $state read, or inside a template a row field — the key itself when the template repeats over this list. Every row whose key, as text, equals it is removed. When none does, nothing changes, so a second press on the same row is harmless, and so is a $state read that is empty when the event runs.

A list that is not in state yet counts as empty. Either action rejects when the path holds something other than a list, and addRow also rejects when the list already holds 500 rows or the new row, once its reads are resolved, is larger than 16,384 characters of JSON or would nest state deeper than 12 levels. A rejection stops the rest of the event, so a refused add leaves the draft as the person typed it. Values are stored as the event read them: a typed $id stays $id.

The preview runs both actions. A host registers their handlers; see the runtime API.

json-render has list actions of its own, pushState and removeState. They run before any handler, so they remove by position, turn a typed $id into a generated id and cannot be bounded. Import refuses them:

Element “order-track” (on.press[0]): pushState is json-render's built-in list action, which removes by position and cannot be bounded; use addRow or removeRow.

Import also refuses a list action on a list no repeat renders, on a list whose repeats disagree on the key, or on a declared collection’s rows, and an addRow that sets the key:

Element “order-track” (on.press[0]): addRow “/deliverySteps” sets “code”, the key; Mica gives every added row a key of its own.

A setState may not write inside a repeated list: a position such as /deliverySteps/0 names another row as soon as rows are added or removed.

Element “order-track” (on.press[0]): setState “/deliverySteps/0/label” writes inside the list “/deliverySteps”; change its rows with addRow, removeRow or $bindItem.

At the list’s own path, setState accepts only a $state copy of another value. A list in document state may hold at most 500 rows; import and the State tab refuse a longer one.

A collection’s rows belong to the host. A document changes one through the host with update or delete, and adds one with create; the listed row changes only when the host answers.

update and delete on a collection name the row they act on with row, whose one key is the collection’s identity. Its value is one of:

  • { "$item": "id" } in a template over the collection: the row whose Button was pressed. Over this collection it must read the identity itself.
  • A $state read, typically the identity a row’s Button copied into a draft.
  • A literal of the identity’s kind, such as "ord_7741". It may not be empty.
  • In a template over another list, { "$item": "<field>" } naming a field of that list’s rows that holds an identity. Over another declared collection the field must be of the identity’s kind (an integer field also serves a number identity), or import refuses it naming both kinds. A local list declares no kinds, so there a missing or unusable value fails at runtime with no-row.

The identity is never an input. create and fetch never take row, and neither does any operation of a single record, which acts on its current record.

Each order card’s Remove from history deletes its own row. Mica asks the authored confirmation first, as for any delete:

{
"order-remove": {
"type": "Button",
"props": {
"label": "Remove from history",
"variant": "outline",
"size": "sm",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": {
"action": "delete",
"params": {
"object": "orders",
"row": {
"id": {
"$item": "id"
}
},
"confirmation": "Remove this order from your history?"
}
}
}
}
}

To edit a host row, use a draft:

  1. A Button in the row copies the row’s fields into ordinary state with a setState record, identity included.
  2. Inputs outside the list edit that draft with $bindState.
  3. A Save Button runs update with row reading the draft’s copied identity and inputs reading the draft’s fields.

The host’s row stays as it was while the person types and while the save is in flight. The order history’s Edit delivery note and Save note do this; Save also clears the draft afterwards, which it skips when the update is rejected, because a rejection stops the rest of the event:

{
"order-edit-note": {
"type": "Button",
"props": {
"label": "Edit delivery note",
"variant": "outline",
"size": "sm",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": {
"action": "setState",
"params": {
"statePath": "/noteDraft",
"value": {
"id": {
"$item": "id"
},
"reference": {
"$item": "reference"
},
"note": {
"$item": "note"
}
}
}
}
}
},
"note-save": {
"type": "Button",
"props": {
"label": "Save note",
"variant": "solid",
"size": "sm",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": [
{
"action": "update",
"params": {
"object": "orders",
"inputs": {
"note": {
"$state": "/noteDraft/note"
}
},
"row": {
"id": {
"$state": "/noteDraft/id"
}
}
}
},
{
"action": "setState",
"params": {
"statePath": "/noteDraft",
"value": {}
}
}
]
}
}
}

When the host answers, Mica merges the answer into the current list by identity, and writes the list, the row count and the operation’s phase in one store write:

Operation On success
delete The row with that identity is removed. If it is no longer listed, the list is unchanged.
update The host’s complete row replaces the row with that identity, in place. If it is no longer listed, the list is unchanged. An answer carrying a different identity is a host-contract error, and no row changes.
create The host’s complete row replaces a listed row with the same identity. Otherwise it is appended only when the collection’s fetch declares no inputs, meaning the host returns the list whole. A queried or paged list is left as it is until its next fetch.

The merge only touches a list that has loaded: until one of the collection’s fetches has succeeded, or the host seeded its rows, a write still reaches the host and settles, but the list and count stay as they are. A later failed fetch keeps the last good list, so it stays loaded.

Nothing refetches on its own. To show a created row in a queried list, follow create with the list’s fetch in the same event: [create, fetch]. In the designer, append the fetch with the Events section’s Add action.

If row resolves to no usable identity when the event runs — an empty draft, or a row field of a local list that is missing or not the identity’s kind, say — the action fails with the error code no-row (There is no row to update.) before the host is asked, and the rest of the event stops.

Import refuses an update or delete of a collection without row, and a row named by another field:

Element “order-remove” (on.press[0]): delete “orders” needs row: { “id”: … }, the identity of the row to delete.
Element “order-remove” (on.press[0]): delete “orders” row “id” reads “reference”; a row of “orders” is named by its identity, { "$item": "id" }.

One operation runs per collection at a time, across all its rows: a write while anything on the collection is in flight is rejected as busy, and so is a fetch during a write. Errors and phases are per collection and operation, not per row, so show them once, beside the list. Row Buttons can use Hide while … is loading.

A collection’s fetch has the usual lifecycle state at /meta/objects/{alias}/operations/fetch/phase and …/error, so loading and error text use Show when as they would for a single record. For the empty state, read the row count the runtime projects at /meta/objects/{alias}/count. A condition on the list itself does not work: an empty list still counts as a value.

{
"empty": {
"type": "Text",
"props": {
"content": "No orders yet. Anything you buy shows up here.",
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": [],
"visible": [
{
"$state": "/meta/objects/orders/operations/fetch/phase",
"eq": "success"
},
{
"$state": "/meta/objects/orders/count",
"eq": 0
}
]
}
}

The count is written together with the list, so the empty text never shows beside rows.

A local list has no projected count. Its empty state reads the list’s first row and inverts the read with "not": true (Not in Show when): the condition holds when /deliverySteps has no row at position 0 — it is empty, or not in state at all.

{
"steps-empty": {
"type": "Text",
"props": {
"content": "No delivery steps yet.",
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/deliverySteps/0",
"not": true
}
}
}

Select a Stack or Grid and open the Inspector’s Repeat section. Turn on Repeat for each row, then pick the List — the suggestions offer each declared collection and each list in document state — and the Row key. For a collection the key is fixed to its identity; for a local list you choose a row field.

Select a Text or Heading inside the template and set its content mode to Row, then Field (a row field) or Position ($index).

A Button or an Input inside the template has the usual Events section. A Set a value action there offers Value, State path, Row field and Record — Record is a field-by-field builder (Add field) with a 32-field cap — and Copy this row, which fills the value with a record of the row’s top-level fields (shown disabled, with the reason, when the import rules would refuse that record, such as for a row of more than 32 fields). An object action’s input can take its value from a Row field. An Input inside a local list’s template has a Row field mode for its value; over a collection that mode is shown disabled, with the reason.

Once the document repeats a local list, the action picker also offers Add a row and Remove a row, each with a List picker of the local lists the document repeats. Add a row shows the key as generated and one control per row field — the fields of the list’s first row in document state, and any field a template reads from its rows — each taking a Value, a State path, in a template a Row field, or Not supplied. Remove a row names its row as This row (automatic) in a template over that list, and otherwise by a State path.

An update or delete of a collection shows a row block for its identity. In a template over the collection it starts as This row (automatic); anywhere else it starts as the State path of the draft’s identity, /drafts/{alias}/{identity}, and it can also take a Value or, in a template over another list, a Row field. The Presentation helpers add:

  • Edit button in each row that copies it into the draft, for an update: a Button in the collection’s template whose setState copies every declared top-level field of the row into /drafts/{alias}. It is shown disabled, with the reason, when no Stack or Grid repeats over the collection or the import rules would refuse the Button.
  • Read inputs and row from draft (or Read row from draft when the operation declares no inputs), which points the inputs and row at that draft.

The Objects view offers all four capabilities for a collection. A capability an action uses, a row Button’s included, cannot be turned off until that action is removed.

The canvas renders the template once, over the first row: the collection’s design sample or the first row in document state. A row read with no value there shows a placeholder naming the list and field, and the row’s Buttons and form controls do nothing on the canvas. The preview renders every row, and there they act.

A two-way $bindState binding may not write a repeated list, anything inside it, or a container of it — each keystroke would replace rows the list is showing. Import refuses it, naming the list and the container that repeats it:

Element “note” (props.value): $bindState “/deliverySteps” would write the list “/deliverySteps”, which element “steps” (repeat) repeats over; edit a row's field with $bindItem inside the template.

To filter, search or sort a collection, see Filter and sort a list.

Nested repeat and moving rows are not part of Mica today; see the limits reference.