Skip to main content

use_reducer

Function use_reducer 

Source
pub fn use_reducer<'s, S: 'static, M: Send + 'static>(
    cx: &mut Cx<'s, '_>,
    reducer: impl FnMut(&mut S, M),
    init: impl FnOnce() -> S,
) -> (State<'s, S>, Dispatch<M>)
Expand description

Hold S in the store and fold queued messages into it with reducer.

Messages are applied when the hook is visited, not at the end of the pass. That keeps reducer an ordinary closure (a pass-end reducer would have to be stored, hence 'static) and saves a frame of latency for messages that arrived from another thread.