nenu-lang / page-state-and-inputs
Stable

Page State And Inputs

  • Initialize state with a concrete type that Page Script can keep stable.
  • Use top-level block-form need for required inputs, optional defaults, and callbacks.
  • Route parameters arrive as bare names from the filesystem route contract.

Concrete Initial State

Page state lives across interactions, so its type must stay stable. Top-level state must use a literal initializer or ?; compute values with function calls inside a function or effect. Empty collections need an explicit element type because [] and {} contain no element evidence.

code
1Expense[] expenses = []2string query = ""3number draft_amount = 04string? draft_note = ?5bool loading = false
  • Keep number inputs in number state when the editor exposes a number contract.
  • Use optional state only when absence is meaningful.
  • Input bindings target simple state names rather than deep entity-field assignments.
  • Project entities and named types are already available to Page Script; do not duplicate their definitions.

Value Inputs With need

code
1need {2  room_id: string3  heading: string = "Room expenses"4  selected_expense: Expense?5}

A field without a default is required from the route or caller. A field with = value has a Page Script input default. Optional type and default are separate ideas: Expense? permits absence, while = ... supplies a value when the caller omits the input.

Callback Inputs

A reusable library component can require callbacks from its owner. Callback input parameters are written name-first inside Page Script need. Ordinary function declarations remain type-first.

code
1need {2  room_id: string3  onSaved(expense: Expense)4  onCancel(): bool5}

Dynamic Route Inputs

A dynamic page path supplies its bracket segment as a bare input name. For a page stored at pages/expenses/[id].page.nenu, use id. Do not invent a route object.

code
1need {2  id: string3}

The Platform User Type

A page or component may accept a User value when its real caller contract supplies one. Treat it as an existing platform type. This guide does not declare User, assume its fields, or make it part of the room application schema.

code
1need {2  current_member: User3}

Common Mistakes

WrongCorrect
Infer expenses = []Expense[] expenses = []
Backend fetch syntax in Page Script needneed { room_id: string }
onSaved(Expense expense) in needonSaved(expense: Expense)
fn handleSaved(expense: Expense)fn handleSaved(Expense expense)
Declare the platform User type locallyConsume the provided User type.

Continue Learning