Skip to content

Scope

Scope stores a View factory as an independent recomposition boundary. Most application code should use [[huxerui::composable]], which generates this boundary automatically while preserving natural function syntax.

[[huxerui::composable]]
View Counter() {
auto count = UseState(0);
return Column {
Text::Format("Count: {}", count),
Button("Increment").OnClick([count] {
count += 1;
}),
}.With(Spacing(12.0F));
}

Explicit construction is useful when a factory is already available as a value:

Scope(content_factory)

The variadic constructor binds a compatible factory and copyable arguments without requiring an application-authored forwarding lambda:

Scope(ProfilePage, user_id)

State, event hubs, task scopes, and lifecycle registrations belong to the scope that creates them. Do not add scopes to every helper function; stateless composition should stay an ordinary function returning View.

Scope adds no semantic role of its own; its returned child supplies the semantic subtree.

  • Scope(std::function<View()> factory).
  • Scope(Factory&& factory, Arguments&&... arguments) for a compatible view factory.
  • Preferred declaration syntax: [[huxerui::composable]] View Component(...).

Read Composition and identity before introducing explicit scope boundaries or keys.

The factory returns one View and runs when the retained scope composes. The variadic form stores decayed, copyable arguments for later invocation; it is not a borrowed call frame. Pass State handles by value when the child must observe future changes. A plain string argument is a value snapshot replaced by a later parent declaration.

Use stable keys on scopes when their siblings reorder. A matching retained scope preserves its UseState and Lifecycle ownership; removing it disposes that lifetime. Avoid reference captures of local variables in a stored factory or cleanup. An empty factory is invalid. Scope itself adds no layout policy or component style; apply sizing to its content or the returned declaration as appropriate.