Let us consider the situation when you have ContentView
and DestinationView
. Both of them depend on some shared data, that typically lies inside the @ObservedObject var viewModel
, that you pass from parent to child either via @EnvironmentObject
or directly inside init()
.
The DestinationView
in this case wants to enrich the viewModel by fetching some additional content inside .onAppear
.
In this case, when using NavigationLink
you might encounter the situation when the DestinationView
gets into an update loop when you fetching content, as it also updates the parent view and the whole structure is redrawn.
When using the List
you explicitly set the row's ids and thus view is not changed, but if the NavigationLink
is not in the list, it would update the whole view, resetting its state, and hiding the DestinationView
.
The question is: how to make NavigationLink
update/redraw only when needed?
AnyView
you can make yourNavigationLinkWrapper
generic (like you did withLazyView
). – Hapsburg