Skip to main content

use_state

Function use_state 

Source
pub fn use_state<'s, T: 'static>(
    cx: &mut Cx<'s, '_>,
    init: impl FnOnce() -> T,
) -> State<'s, T>
Expand description

Hold T in the store, initialising it on the first visit.

Returns a guard that derefs to T. The guard borrows the store, not the Cx, so sibling event handlers can each take it mutably in turn.