pub trait UseState {
fn use_state<F, T>(&mut self, initializer: F) -> State<T>
where
F: FnOnce() -> T,
T: 'static;
}
Expand description
A hook to add state to a component.
Required Methods§
sourcefn use_state<F, T>(&mut self, initializer: F) -> State<T>where
F: FnOnce() -> T,
T: 'static,
fn use_state<F, T>(&mut self, initializer: F) -> State<T>where
F: FnOnce() -> T,
T: 'static,
Returns a State
initialized with the provided initializer
. The initializer
is only called once,
when the UseState::use_state
hook is first called, and a memoized value is used in future calls.
When a State
is mutated through its methods, it will trigger a re-render of the component that it
was first defined in.
This is inspired by React’s useState
hook.