How to use a viewStore.somevariable like @State

Hi! I'm get starting to learn about TCA and I'm have the follow scenario:
I need to get a text from a textfield in SwiftUI and in other scenario, i needed to use @State var varName to get the current text on my TextField.
How can I do this?

Check out the "bindings basics" example from the SwiftUI case studies demo: https://github.com/pointfreeco/swift-composable-architecture/blob/8cc8492b9f3930491e74d2579584c1e9d20bedb0/Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-Bindings-Basics.swift

Because TCA does unidirectional data flow, you must define an action to mutate state. In this case we have a text field with an associated text state:

textChange action:

The reducer updates state with the action:

And in the view, the view store derives a binding by describing the state and action:

While there are a few steps to get there, once set up you can fully control the stream of text field events and do a lot of interesting, testable things!

Yes, I read about binding but I'm trying to bind a text only when I did tap a button. Something like this:

hey @stephencelis thanks!
Finally I understood!

Terms of Service

Privacy Policy

Cookie Policy