pub fn use_memo<T, D>(
cx: &ScopeState,
dependencies: D,
callback: impl FnOnce(<D as UseFutureDep>::Out) -> T
) -> &Twhere
T: 'static,
D: UseFutureDep,
Expand description
A hook that provides a callback that executes if the dependencies change. This is useful to avoid running computation-expensive calculations even when the data doesn’t change.
- dependencies: a tuple of references to values that are
PartialEq
+Clone
Examples
#[inline_props]
fn Calculator(cx: Scope, number: usize) -> Element {
let bigger_number = use_memo(cx, (number,), |(number,)| {
// This will only be calculated when `number` has changed.
number * 100
});
render!(
p { "{bigger_number}" }
)
}
fn app(cx: Scope) -> Element {
render!(Calculator { number: 0 })
}