State
state!(init) allocates a hook slot that survives destroy/rebuild cycles. Slots
are ordered by call site and namespaced by the current GUI root_name.
fn app() -> impl Into<Widget> { let count = factorio_rs_gui::state!(0); let label = format!("Count: {}", count.get()); // ...}| Call | Effect |
|---|---|
state!(init) |
Create / resume a hook with initial i32 |
state.get() |
Read current value |
state.set(value) |
Write value and rebuild this root |
state! expands to State::use_state. Prefer the macro at the top of app.
- Call hooks in a stable order every rebuild (same as React hooks).
- Do not put hooks behind conditionals that change between rebuilds.
- Captions are not live bindings, use
format!and letsetrebuild the tree. - Values live in your mod’s
storageunder keys likefrg:{root}:hook_N.
Types today
Section titled “Types today”Hooks are limited to i32 (for now). Store richer data in your own storage keys and keep a
counter (or flag) in state! to trigger rebuilds.
See also: Lifecycle, Reactive GUI.