Mobile App Development
Lesson 2 of 3 9 min +70 XP

State & Events

Making an app respond.

What you'll learn

  • Define state
  • Handle a user event
  • Explain re-rendering on state change
The app that remembers

Tap a heart and it fills red and stays that way — the app remembered your tap. 'State' is the app's memory, and events (your taps and swipes) are what change it, making a static screen come alive.

State is what changes

State is the data an app remembers — the current tab, a counter, a form's text. When a user event fires (a tap, a keystroke), a handler updates the state, and the UI re-renders to reflect the new value. This loop — event → update state → re-render — is the heartbeat of an interactive app.

onTap: count = count + 1   →   the label re-renders showing the new count
Lab · Trace the loop
  1. A counter starts at 0. The user taps '+'.
  2. Which handler runs, and what does it change?
  3. What does the screen show next, and why?

What you should see: The tap fires the increment handler, state goes 0 → 1, and the UI re-renders to show 1 — event, state update, re-render.

Knowledge Check

+18 XP / correct

1. State is…

2. When state changes, the UI…