Struct sycamore_reactive::StateHandle [−][src]
pub struct StateHandle<T: 'static>(_);
Expand description
A readonly Signal
.
Returned by functions that provide a handle to access state.
Use Signal::handle
or Signal::into_handle
to retrieve a handle from a Signal
.
Implementations
Get the current value of the state. When called inside a reactive scope, calling this will add itself to the scope’s dependencies.
Example
use sycamore_reactive::*;
let state = Signal::new(0);
assert_eq!(*state.get(), 0);
state.set(1);
assert_eq!(*state.get(), 1);
Get the current value of the state, without tracking this as a dependency if inside a reactive context.
Example
use sycamore_reactive::*;
let state = Signal::new(1);
let double = create_memo({
let state = state.clone();
move || *state.get_untracked() * 2
});
assert_eq!(*double.get(), 2);
state.set(2);
// double value should still be old value because state was untracked
assert_eq!(*double.get(), 2);
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for StateHandle<T>
impl<T> !Send for StateHandle<T>
impl<T> !Sync for StateHandle<T>
impl<T> Unpin for StateHandle<T>
impl<T> !UnwindSafe for StateHandle<T>
Blanket Implementations
Mutably borrows from an owned value. Read more