# Live Todo App

- **Section:** Getting Started
- **URL:** https://refast.fastapicloud.dev/docs/todo-live
- **Markdown:** https://refast.fastapicloud.dev/docs/todo-live.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/getting_started/todo_app_live.py
- **Live examples:** the widgets on this page need a browser; open the URL above to try them.
- **Applies to:** refast 0.12.2

This is a live demo of the Todo App built in the Quick Tour.
                It is running right here inside the documentation site!

## ToDo List

## What the demo is doing

The list above is the whole app — 60-odd lines in
[`docs/pages/getting_started/todo_app_live.py`](https://github.com/idling-mind/refast-docs/blob/main/docs/pages/getting_started/todo_app_live.py),
including this explanation. Three pieces carry it.

### The input writes into state without a round trip

```python
rc.Input(
    name="new_todo",
    id="new-todo-input",
    on_change=ctx.save_prop("new_todo", debounce=300),
)
```

`ctx.save_prop` tells the browser to keep the field's value in a variable on the
server, so typing does not re-render anything. The `debounce` waits for a pause
in typing before the value is sent.

### Adding reads the saved value and appends to a list

```python
async def add_todo(ctx: Context, new_todo: str):
    todos = ctx.state.get("todos", [])
    todos.append({"id": str(uuid4()), "text": new_todo, "completed": False})
    ctx.state["todos"] = todos
    await ctx.update_props("new-todo-input", {"value": ""})
    await ctx.replace("todo-list", render_todo_list(ctx))
    await ctx.show_toast(f'Added todo: "{new_todo}"', variant="success")
```

`props=["new_todo"]` on the button's callback is what delivers `new_todo` as an
argument — the framework sends the saved value with the event rather than
keeping it in the component. Clearing the field is a prop update on its id;
redrawing the list is `ctx.replace` on the list's id. The uuid exists so
`mark_todo` can find the row it toggled.

### Ticking a box re-renders the list, not the page

```python
rc.Checkbox(
    checked=todo["completed"],
    on_change=ctx.callback(mark_todo, todo_id=todo["id"]),
)
```

Each checkbox closes over its todo's id, so one handler serves the whole list.

## Where to read further

- [Quick Tour](https://refast.fastapicloud.dev/docs/quick-tour) — this app built step by step
- [Callbacks & Events](https://refast.fastapicloud.dev/docs/concepts/callbacks) — `props`, `bound_args`, debounce
- [State & Store](https://refast.fastapicloud.dev/docs/concepts/state) — what `ctx.state` covers and when to use
  the browser stores instead
- [Updates](https://refast.fastapicloud.dev/docs/concepts/updates) — `replace`, `append`, `update_props`

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
