Function sycamore_reactive::create_scope [−][src]
pub fn create_scope<'a>(callback: impl FnOnce() + 'a) -> ReactiveScope
Expand description
Creates a new reactive root / scope. Generally, you won’t need this method as it is called
automatically in render
.
The parent of the created ReactiveScope
is automatically set to the current scope.
If this behavior is not intended, see create_child_scope_in
.
Example
use sycamore_reactive::*;
let trigger = Signal::new(());
let counter = Signal::new(0);
let scope = create_scope(cloned!((trigger, counter) => move || {
create_effect(move || {
trigger.get(); // subscribe to trigger
counter.set(*counter.get_untracked() + 1);
});
}));
assert_eq!(*counter.get(), 1);
trigger.set(());
assert_eq!(*counter.get(), 2);
drop(scope);
trigger.set(());
assert_eq!(*counter.get(), 2); // should not be updated because scope was dropped