---
title: "Your first component"
description: "A complete first component, a counter with state, two actions and a view, and how to compile it and run it in a scaffolded app."
modificationDate: "2026-11-30"
---

> ## 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.

# Your first component

<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/learn/contract-for-humans/your-first-component: <what was wrong or missing>"`

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

</AgentInstructions>

This is a complete file. Save it as `app.contract` and compile it with the command
above. To run it, put it in a scaffolded app in place of its `app.contract`, delete
the scaffold's `greeting` entry from `sources` in `app.ts`, and replace
`app.test.contract` with the test under
[Testing](https://exact.expo.dev/learn/contract-for-humans/testing-diagnostics-and-delivery.md).

```contract
component Counter
  state count = 0
  action increment
    count = count + 1
  action reset
    count = 0
  view
    column gap=12
      text `Count: ${count}` role="heading" aria-level=1 testId="count"
      row gap=8
        button press=increment testId="increment"
          text "Add one"
        button press=reset testId="reset"
          text "Reset"
```

The first component is the app's root. `state` holds a value, and an `action`
changes it. `view` describes the visible tree. Indentation makes the two buttons
children of the row. `press=increment` binds an action; it does not call that
action while building the view. A template puts the current count into text.

`testId` gives the driver a stable name for a node. It is separate from `id`,
which host commands and geometry functions use.
