Skip to content

Send actions to store within tabView selection #1100

Answered by tgrapperon
ivangodfather asked this question in Q&A
Discussion options

You must be logged in to vote

In SwiftUI, this is achieved through a Binding, which is a value that you can read and write.
There are several ways to achieve this in TCA, but the closest to what you have there is to replace viewStore.selectedTab by:

viewStore.binding(
  get: { state in 
    state.selectedTab 
  }, 
  send: { tab in 
    AppAction.selectedTab(tab)
  }
}

or equivalently:

viewStore.binding(get: \.selectedTab, send: AppAction.selectedTab)

There are other means to achieve this in the library, like using a binding() higher-order reducer, but they are more involved. You can look at the case studies for more informations about them.

Now, your implementation of TabView with a selection is not complete, even i…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ivangodfather
Comment options

Answer selected by ivangodfather
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants