X01

Error

State and reactivity

X01 — An assignment to something that cannot change

A const, a derived value, a prop, a route parameter, a loop variable or an action is assigned to. At run time the write throws, or changes a copy nothing reads.

What the compiler said

error[X01]: `LIMIT` is a `const`, and nothing may assign to it --> src/App.wf:4:33 | 4 | Button("More") { on click { LIMIT = 4 } } | ^^^^^ = help: Declare it `state` if it changes; a constant is the same on every page = docs: https://webfluent.monzeromer.dev/errors/X01

The fix

Broken

wf

const LIMIT = 3 page P(path: "/", title: "T", description: "D") { Heading("Limit {LIMIT}").h1 Button("More") { on click { LIMIT = 4 } } }

Fixed

wf

page P(path: "/", title: "T", description: "D") { state limit = 3 Heading("Limit {limit}").h1 Button("More") { on click { limit = 4 } } }

Hold what changes in a state. A derived value changes when what it reads does; a prop is its caller's (emit an event so the caller changes it); a route parameter is the address's (navigate); a loop variable is one pass's copy (change the item through its list).

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

lints cannot lower it: it would ship a broken page.