Function sycamore::reactive::create_selector
source · [−]pub fn create_selector<'a, U>(
cx: BoundedScope<'a, 'a>,
f: impl FnMut() -> U + 'a
) -> &'a ReadSignal<U>where
U: 'a + PartialEq<U>,
Expand description
Creates a memoized value from some signals.
Unlike create_memo
, this function will not notify dependents of a
change if the output is the same. That is why the output of the function must implement
PartialEq
.
To specify a custom comparison function, use
create_selector_with
.
Example
let state = create_signal(cx, 0);
let double = create_selector(cx, || *state.get() * 2);
assert_eq!(*double.get(), 0);
state.set(1);
assert_eq!(*double.get(), 2);