sycamore::reactive

Function on

pub fn on<T>(
    deps: impl Trackable + 'static,
    f: impl FnMut() -> T + 'static,
) -> impl FnMut() + 'static
Expand description

A helper function for making dependencies explicit.

§Params

  • deps - A list of signals/memos that are tracked. This can be a single signal or it can be a tuple of signals.
  • f - The callback function.

§Example

let state = create_signal(0);

create_effect(on(state, move || {
    println!("State changed. New state value = {}", state.get());
}));
// Prints "State changed. New state value = 0"

state.set(1);
// Prints "State changed. New state value = 1"