Function use_memo

Source
pub fn use_memo<T, D>(create: impl FnOnce() -> T, deps: Deps<D>) -> Memo<T>
where T: 'static, D: PartialEq + 'static,
Expand description

Returns a persisted, memoized value.

This will recompute the value with the given closure whenever the given dependencies has changed from last render. This optimization helps to avoid expensive calculations on every render.

ยงExample

fn render(&self) -> VNode {
  let a = self.a;
  let b = self.b;
  let memo = use_memo(|| compute_expensive_value(a, b), Deps::some((a, b)));

  let vnode = h!(div).build(*memo.value());
  vnode
}