Skip to main content

Module hooks

Module hooks 

Source
Expand description

TUI hooks system — co-located widget state, SDK subscriptions, and animation.

Modeled after React hooks but adapted for Rust’s ownership model and ratatui’s immediate-mode rendering. Three primitives:

  • use_state<V>(key, default) — Persistent local state across renders
  • use_watch(property_handle) — Subscribe to SDK property, return current value
  • use_animation(key, active) — Request periodic re-renders when active

§Calling Convention

use_state returns &mut V which borrows &mut self on Hooks. To avoid borrow conflicts, call hooks in this order:

  1. use_watch — returns owned Option<V>, borrow released immediately
  2. use_animation&mut self borrow released immediately
  3. use_state — must be called last or in a scoped block

§Frame Lifecycle

hooks.begin_frame()     // reset access tracking
terminal.draw(...)      // widgets call hooks
hooks.end_frame()       // evict unaccessed state + handles

Structs§

Hooks
General-purpose hooks system for TUI widget state management.
ProgressState
Client-side progress interpolation state for a single group.
RenderContext
Render context passed to all render functions.