Incular logoIncular
API ReferenceState & Async

Effect

Owner-mounted side effects queued for the reactive phase.

Owner-mounted side effect. Never runs during build; mount queues the initial run for the reactive phase.

MethodEffect
new(callback)Create with side-effect closure
mount()Bind to current builder; idempotent
is_mounted()Mount state query
dispose()Unmount and release
use incular::prelude::*;
use incular::reactive::Effect;

fn main() {
    let count = Signal::new(0u32);
    let logger = Effect::new({
        let count = count.clone();
        move || println!("count changed: {}", count.get())
    });
    let app = Application::new(move |_cx| {
        logger.mount();
        let tapped = count.clone();
        let shown = count.clone();
        Container::builder()
            .padding(EdgeInsets::all(24.0))
            .alignment(Alignment::CENTER)
            .child(
                GestureDetector::new(Text::new(format!("Count: {}", shown.get())))
                    .on_tap(move || tapped.update(|c| *c += 1)),
            )
            .build()
            .into()
    })
    .expect("valid application");
    incular::run(app).expect("run application");
}

Use effects for logging, persistence triggers, and subscriptions — never for rendering. Writes to Signals from inside the effect callback are legal.

Related: Memo, Action.