You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m using swift‑dependencies alongside TCA in a SwiftUI app with a single “root” store that configures all my dependencies. In one part of the UI I need:
A TCA‑powered parent view (MainView) that owns the root store
A plain SwiftUI child view (UserListView) that does not use TCA directly
A nested TCA‑powered leaf view (UserView) that needs its own store but must share exactly the same dependencies that MainView set up
I want to avoid passing the full store down through every initializer and guarantee that the UserReducer store in UserListView is created exactly once (not on every SwiftUI redraw)
No extra init parameters on MainView or UserListView
One‑time store creation for UserView, even though its parent is plain SwiftUI
All reducers resolve their dependencies via @Dependency(\.…) from the same root DependencyValues
Injecting the full DependencyValues into SwiftUI’s environment variable at the app root.
Defining a StoreHost helper that wraps any Store<State,Action> in a @StateObject, ensuring one‑time creation.
In UserListView, reading the injected DependencyValues via @Environment(.dependencyValues), then creating the store for UserView
Question
Has anyone found a more idiomatic or streamlined way, perhaps leveraging more of swift‑dependencies or TCA patterns—to embed a child store inside a non‑TCA SwiftUI container, share the same DependencyValues, avoid prop‑drilling, and keep the intermediate view completely free of TCA?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I’m using swift‑dependencies alongside TCA in a SwiftUI app with a single “root” store that configures all my dependencies. In one part of the UI I need:
I want to avoid passing the full store down through every initializer and guarantee that the
UserReducer
store inUserListView
is created exactly once (not on every SwiftUI redraw)MainView
orUserListView
UserView
, even though its parent is plain SwiftUI@Dependency(\.…)
from the same root DependencyValuesWhat I’ve tried testApp.zip
Question
Has anyone found a more idiomatic or streamlined way, perhaps leveraging more of swift‑dependencies or TCA patterns—to embed a child store inside a non‑TCA SwiftUI container, share the same DependencyValues, avoid prop‑drilling, and keep the intermediate view completely free of TCA?
Beta Was this translation helpful? Give feedback.
All reactions