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: swift-composable-architecture/01-GettingStarted-Bindings-Basics.swift at 8cc8492b9f3930491e74d2579584c1e9d20bedb0 · pointfreeco/swift-composable-architecture · GitHub
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!