sycamore::reactive

Function create_effect

pub fn create_effect(f: impl FnMut() + 'static)
Expand description

Creates an effect on signals used inside the effect closure.

ยงExample

let state = create_signal(0);

create_effect(move || {
    println!("new state = {}", state.get());
});
// Prints "new state = 0"

state.set(1);
// Prints "new state = 1"

create_effect should only be used for creating side-effects. It is generally not recommended to update signal states inside an effect. You probably should be using a create_memo instead.