withState(_:)

Calls the given closure with a snapshot of the current state of the store.

Store.swift:205
@MainActor func withState<R>(_ body: (_ state: State) -> R) -> R

Parameters

body

A closure that takes the current state of the store as its sole argument. If the closure has a return value, that value is also used as the return value of the withState method. The state argument reflects the current state of the store only for the duration of the closure’s execution, and is only observable over time, e.g. by SwiftUI, if it conforms to ObservableState.

Returns

The return value, if any, of the body closure.

A lightweight way of accessing store state when state is not observable and state is unavailable.