Skip to content

Navigation is rendered twice #1366

Answered by stephencelis
dadixon asked this question in Q&A
Discussion options

You must be logged in to vote

@dadixon Whenever you encounter a WithViewStore like this:

WithViewStore(self.store) {  }

Everything in the braces will be re-evaluated whenever any piece of state in self.store changes, even if it only needs to observe much less state. In the case of complex flows like navigation, SwiftUI has bugs that can cause problems when a parent view is recomputed while you're drilled down to some other view.

In your case above, your WithViewStore only needs to observe the binding's id:

-WithViewStore(self.store) { viewStore in
+WithViewStore(self.store, observe: \.selectedChild?.id) { viewStore in
     List {
         ForEach(viewStore.childStates) { childState in
             NavigationLink(
   …

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@stephencelis
Comment options

@dadixon
Comment options

@stephencelis
Comment options

@dadixon
Comment options

@dadixon
Comment options

Answer selected by dadixon
Comment options

You must be logged in to vote
0 replies
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