Function sycamore_reactive::on_cleanup[][src]

pub fn on_cleanup(f: impl FnOnce() + 'static)
Expand description

Adds a callback function to the current reactive scope’s cleanup.

Example

use sycamore_reactive::*;

let cleanup_called = Signal::new(false);

let scope = create_root(cloned!((cleanup_called) => move || {
    on_cleanup(move || {
        cleanup_called.set(true);
    })
}));

assert_eq!(*cleanup_called.get(), false);

drop(scope);
assert_eq!(*cleanup_called.get(), true);