---
title: "Recipe: a component that needs a timer"
description: "A bounded child owns its timer; an activity gate stops it while hidden."
modificationDate: "2026-11-17"
---

> ## 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 component that needs a timer

<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/timer-in-a-component: <what was wrong or missing>"`

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

</AgentInstructions>

A child at a bounded use can own a task and the state that gates it. Each
instance starts and stops its own timer ([timers](https://exact.expo.dev/recipes/timers.md) has the schedules):

```prompt Give a component a timer
Give a bounded child component in the Exact app in this folder its own timer and gate. Use https://github.com/expo/exact/blob/main/docs/recipes/timer-in-a-component.md as the source for each step. The Exact checkout has the same page at docs/recipes/timer-in-a-component.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 name the component that needs the timer, find it from what the app does and ask me before you write code.
3. Check that the component is used outside data-sized repetition: under `if` or `match`, in a tab, or in a navigation stack. Declare the `task`, its gate state and its stepping action in that component. Tasks under a data-sized `for` or in a virtualized list stay out; use one shared task in the enclosing screen for those rows.
4. Each instance owns its task and stops it when destroyed. A hidden instance stays alive: pass activity as a prop and include it in `when` if the timer should stop while hidden. Use `key=` when changing a value should restart the timer.
5. Keep the existing tests passing without changing what they check. Add a test in app.test.contract that starts the timer (`tap "<id>" drag 0 0 hold <ms>` for a held control, or a `tap`), expects state while it runs, and after it stops runs `clock +<ms>` and expects the state unchanged.
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 component owns the task, what gates it, what the tests and checks reported, and the launch command for each target platform.
```

```contract
component App
  view
    column
      Capsule(id="left")
      Capsule(id="right")

component Capsule
  props
    id: string
  state charge = 0
  state holding = false
  task charging when holding and charge < 100
    every(16, step)
  action step
    charge = min(100, charge + 2)
  action hold(on: bool)
    holding = on
  view
    column
      button pointerdown=hold(true) pointerup=hold(false) testId=id
        text (charge < 100 ? "Hold to charge" : "Charged")
      progress value=charge max=100
```

The task's action runs in its instance: charging the left capsule does not
change the right one. Destroying a capsule stops its task. A hidden tab can
remain alive; gate its work on activity passed from the router. `key=` restarts
a timer when its key changes, as at the root. Reload restarts timers over
compatible carried state.

A task cannot belong to a component under a data-sized `for` or in a virtualized
list. Put shared timing in the enclosing screen and pass its value or action to
those rows. `every(frame, …)` is allowed at bounded uses; each armed instance
runs an action per frame.
