U09

Warning

Declared and never read

U09 — An unkeyed loop whose items hold state

With no by, a change to the list redraws every item, and what an item holds — a field being typed in, a component's own state — starts again.

What the compiler said

warning[U09]: this `for` has no `by`, and each item holds a `Input`, which starts again whenever the list changes --> src/App.wf:4:5 | 4 | for r in rows { Input(bind: r.name, label: "Name") } | ^^^ = help: Key it: `for r in … by r.id` = docs: https://webfluent.monzeromer.dev/errors/U09

The fix

Broken

wf

page P(path: "/", title: "T", description: "D") { state rows = [{ id: 1, name: "a" }] Heading("Rows").h1 for r in rows { Input(bind: r.name, label: "Name") } }

Fixed

wf

page P(path: "/", title: "T", description: "D") { state rows = [{ id: 1, name: "a" }] Heading("Rows").h1 for r in rows by r.id { Input(bind: r.name, label: "Name") } }

Key it: for r in rows by r.id.

Each example is a whole program: it is all of src/App.wf in a project with no other .wf file (trying an example).

Why this rule exists

Warning.

lints may lower it:

"lints": { "U09": "off" } // wf-allow(U09)