Value Change Triggers Twice in Shared SwiftUI TextField Component (Not Using TCA) #3730
Replies: 1 comment 1 reply
-
Hi @faithinker, the issue you linked to above, #1093, shows that the double action being sent is a vanilla SwiftUI problem, not a TCA problem. And so wrapping a There is another discussion of this problem in #808 where we show that you can introduce a
No, there is no problem with that in general, but also your We think generic, reusable TCA components really only makes sense for significantly complicated components. Typically things that have very nuanced logic and side effects that you would like to be able to test in isolation and have guarantees that it works when plugged into larger systems. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I’m building a reusable common TextField component to be used across multiple screens in a TCA-based app.
To avoid nested reducer complexity and based on discussions like #1093 and #3515, I intentionally implemented this TextField as a pure SwiftUI view, not using TCA inside the component itself.
However, I’m facing an issue:
When I type into the field, the parent view’s onChange (or .binding(...)) triggers twice for every input — once for .onAppear (due to initial focus) and again for every keystroke.
Here’s the situation:
The child CommonTextField is a plain SwiftUI component
The parent reducer holds the state
The Parent View
Result Log ScreenShots
Questions:
1. Is there a recommended way to suppress the redundant initial event on appear or focus?
2. Should I write a wrapper like:
as a workaround?
I have another question.
Is creating shared components using TCA against the principles of the Composable Architecture?
For example, like the code below.
Component Child Reducer
Component Child View
Login Feature
LoginView
Any thoughts or official best practices would be appreciated!
Thanks 🙌
Beta Was this translation helpful? Give feedback.
All reactions