hooks
module · ferroui-view · v0.5.0
module hooks
Hooks: the state of a component that runs again.
A component made with rerender or
#[component(rerender)] runs its function again whenever a signal it read
while it ran changes, or its parent runs again; the elements it returns are
compared with those of the run before and the controls are patched
(docs/declarative-ui.md, section 8). What has to outlive one run is kept
in hooks: each use_* call has a slot of the component, found by the order
of the calls, so a hook is called on every run, in the same order, never in
a condition or a loop whose length changes.
use_hook: a value made on the first run and handed back on the next ones.use_signal: a signal kept across runs. Reading it in the function makes the component run again when it changes; reading it in a property (text: count) changes only that property.use_memo: a memo kept across runs.use_effect: an effect started once the first run's controls are in place, which runs again when the signals it read change.use_effect_with: a closure run once the controls are in place, and again on a run whose dependencies differ; what it registered withon_cleanupruns before the next call and when the component is taken out.use_future(async_data.rs): a future started once the controls are in place and again on a run whose dependencies differ, and its state as a signal.
Everything a hook makes belongs to the component and is disposed when the
component is taken out. Signals made with signal in the
function itself belong to that run and are made again on the next one.
Contents
use_hook— functionuse_signal— functionuse_memo— functionuse_effect— functionuse_effect_with— functionuse_parent_control— functionuse_parent_property— functionuse_data_context_value— functionuse_theme_variant— functionuse_resource— functionuse_data_context— functionuse_resource_as— function
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.