effect_once!() { /* proc-macro */ }Expand description
The effect_once! macro for creating order-independent effects that run once.
This is the recommended way to run one-time initialization effects in Telex. Unlike traditional hooks, effects created with this macro can be used conditionally or in any order.
Each macro invocation creates a unique anonymous type as the key, ensuring each call site gets its own independent effect.
§Examples
Basic usage - runs once on first render:
ⓘ
effect_once!(cx, || {
println!("App initialized");
|| {
println!("App cleanup");
}
});Safe in conditionals:
ⓘ
if feature_enabled {
effect_once!(cx, || {
setup_feature();
|| cleanup_feature()
});
}