IfLetStore

A view that safely unwraps a store of optional state in order to show one of two views.

IfLetStore.swift:40
iOS
deprecated
macOS
deprecated
tvOS
deprecated
watchOS
deprecated
@MainActor struct IfLetStore<State, Action, Content> where Content : View

When the underlying state is non-nil, the then closure will be performed with a Store that holds onto non-optional state, and otherwise the else closure will be performed.

This is useful for deciding between two views to show depending on an optional piece of state:

IfLetStore(
  store.scope(state: \.results, action: { .results($0) })
) {
  SearchResultsView(store: $0)
} else: {
  Text("Loading search results...")
}