Function freya::prelude::use_const

pub fn use_const<T>(
    cx: &ScopeState,
    initial_state_fn: impl FnOnce() -> T
) -> &UseConst<T>where
    T: 'static,
Expand description

Store constant state between component renders.

UseConst allows you to store state that is initialized once and then remains constant across renders. You can only get an immutable reference after initalization. This can be useful for values that don’t need to update reactively, thus can be memoized easily

struct ComplexData(i32);

fn Component(cx: Scope) -> Element {
  let id = use_const(cx, || ComplexData(100));

  cx.render(rsx! {
    div { "{id.0}" }
  })
}