Skip to content

Navigation: Problem of understanding ViewStore Binding value #866

Answered by stephencelis
REF2111 asked this question in Q&A
Discussion options

You must be logged in to vote

What we don't understand is how the value in the send closure of the binding can be true without having sent the loginButtonTapped action in the first place.

The send part of ViewStore.binding is the set part of a vanilla SwiftUI binding, which gives the view the ability to influence the value in a source of truth the binding was derived from. We could create a binding from scratch using Binding.init and it would look like this:

Binding(
  get: { viewStore.isTwoFactorActive },
  set: { isActive in
    if isActive {
      viewStore.send(.loginButtonTapped)
    } else {
      viewStore.send(.twoFactorDismissed)
    }
  }
)

So the value in set is sent from the view in order to influence th…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@blg-al
Comment options

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