use_hook

Function use_hook 

Source
pub fn use_hook<T>(init: impl FnOnce() -> T) -> T
where T: Clone + 'static,
Expand description

This is the foundational hook used by all. It’s simple, it accepts an initialization callback whose return value will be stored in this component instance until its dropped. In subsequent renders the returned value of the function will be a Cloned value of what had been previously returned by the initialization callback.

let my_cloned_value = use_hook(|| 1);

In order to maintain the concept of “instance”, other hooks use State::create to store their values. One could also use Rc<RefCell<T>> but then you would not be able to make your hook values Copy.