Skip to content

Problem when using TCA combined with iOS 16 NavigationStack #1692

Answered by mbrandonw
WesleyHilhorst asked this question in Q&A
Discussion options

You must be logged in to vote

The problem is in this line. This creates a whole new store from scratch every time the view is recreated, which causes any state changes to be lost and all effects to be cancelled.

This is why in TCA, when creating child features, one scopes an existing store to pass down to the child instead of constructing a whole new one from scratch.

However, this store-scoping style does not immediately play nicely with NavigationStack. And really this is a vanilla SwiftUI problem too. As we showed in the most recent episode, if you want be able to observe what is happening in each screen of a stack you are forced to put a full-blown observable object in each case of the destination enum, which then…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by WesleyHilhorst
Comment options

You must be logged in to vote
2 replies
@mbrandonw
Comment options

@WesleyHilhorst
Comment options

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