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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.