---
title: "Recipe: a remembered setting"
description: "A setting the app keeps across launches — a tip percentage, °C or °F — is a root state that ends in persist (LLP 1116 D5)."
modificationDate: "2026-11-20"
---

> ## 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 remembered setting

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

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

</AgentInstructions>

A setting the app keeps across launches — a tip percentage, °C or °F — is a root
`state` that ends in `persist` (LLP 1116 D5). There is no data module, grant or
JSON to write: the runner reads the store before the first frame and writes it
after every commit that changes the state.

```prompt Keep a setting across launches
Make the Exact app in this folder remember a setting across launches. Use https://github.com/expo/exact/blob/main/docs/recipes/persisted-setting.md as the source for each step. The Exact checkout has the same page at docs/recipes/persisted-setting.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 setting to keep, list the choices the app already has and ask me which ones. A setting is a choice the person makes (a filter, a sort order, units, a toggle), not text they are typing or a draft.
3. For each setting, add `persist` to its root `state` in app.contract. If the setting is a child component's state, move it to the root and pass it down as a prop. Persist only a number, string or bool, or an option or list of one; never a record, a list of records or a derive. Write no data module, grant or storage code.
4. If a setting is a choice of one value, make it a `radiogroup` of radios, each `aria-checked` when it is the value.
5. In app.test.contract, add a test that changes each setting, runs `reload`, and expects the new value, and a test that a fresh install starts from the declared value.
6. 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 7) and report it; do not keep trying.
7. 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.
8. Tell me which settings the app now keeps, what the tests and verify reported, and how to see it by hand: `bun exact.mjs agent web --storage s1 "<a tap>"`, then `bun exact.mjs agent web --storage s1 --keep-storage state`.
```

```contract
component App
  state tipPercent = 18 persist
  state units = "C" persist
  action tip(p: number)
    tipPercent = p
  action unit(u: string)
    units = u
  view
    column padding=16 gap=12
      text "Tip" role="heading" aria-level=2
      row role="radiogroup" aria-label="Tip"
        for p in [15, 18, 20, 25] key=p
          button role="radio" aria-checked=(tipPercent == p) press=tip(p) testId=`tip-${p}` flex=1
            text `${p}%`
      text "Temperature" role="heading" aria-level=2
      row role="radiogroup" aria-label="Temperature"
        button role="radio" aria-checked=(units == "C") press=unit("C") testId="unit-c" flex=1
          text "°C"
        button role="radio" aria-checked=(units == "F") press=unit("F") testId="unit-f" flex=1
          text "°F"
```

Each test in `app.test.contract` gets its own store. A leading `stored` line
puts a JSON value in it before the first frame, so you can test an upgrade from
an earlier build. On `reload` the app reads whatever the test has saved.

```contract-test
test "an upgrade keeps the earlier choice"
  stored units "F"
  expect state units == "F"
  tap "unit-c"
  tap "tip-20"
  reload
  expect state units == "C"
  expect state tipPercent == 20

test "a fresh install starts from the declared values"
  expect state tipPercent == 18
  expect state units == "C"
```

Run it with `bun exact.mjs test web` (or `test ios`, `test linux`). To see it by
hand, drive twice with the same store: `bun exact.mjs agent web --storage s1 "tap
tip-20"`, then `bun exact.mjs agent web --storage s1 --keep-storage state` shows `tipPercent:
20`. A drive without `--storage` starts from the declared values and keeps nothing
past the drive.

What to know:

- **The first frame.** A kept value of the state's type replaces the declared one.
  A missing value keeps the declared one, and so does a value of another shape
  (the state's type changed since it was kept); `logs` names that one.
- **Where.** The page's `localStorage`, `UserDefaults` on Apple, a file on Linux, keyed by the
  state's name: renaming the state forgets it.
- **Only small settings.** A number, string or bool, or an option or list of one,
  at most 16 KB as JSON. `persist` on a record or a list of records is refused
  (`type-persist-type`): keep app data in a source. A child component's state
  cannot persist (`type-persist-child`): keep the setting in the root and pass it
  down as a prop.
- **A derive is never persisted.** Persist what it reads (`syntax-persist-derive`).
- **A choice of one value** is a `radiogroup` of radios, each `aria-checked` when it is
  the value: the platform's segmented control, the arrows moving it on the web. A
  `tablist` is for switching panels.
