pub fn use_selector<R: PartialEq>(
    cx: &ScopeState,
    f: impl FnMut() -> R + 'static
) -> ReadOnlySignal<R>
Expand description

Creates a new Selector. The selector will be run immediately and whenever any signal it reads changes.

Selectors can be used to efficiently compute derived data from signals.

use dioxus::prelude::*;
use dioxus_signals::*;

fn App(cx: Scope) -> Element {
    let mut count = use_signal(cx, || 0);
    let double = use_selector(cx, move || count * 2);
    count += 1;
    assert_eq!(double.value(), count * 2);
  
    render! { "{double}" }
}