Closed blommegard closed 2 years ago
Not that I'm aware of, no. But this generally shouldn't cause for any problems.
If you're fetching data it's advised to do this in a view's .onAppear
.
Text("One")
.onAppear { print("Hello One") }
Regardless of how often you're navigating, you'll notice this will only get called once :smile: This is the perfect moment for views to fetch asynchronous data or perform tasks that only need to run the first time they appear.
An example:
struct SomeAsyncDataView: View {
@StateObject private var viewModel = MyViewModel()
var body: some View {
Group {
if !viewModel.data.isEmpty {
Route(path: "subroute/*", content: AnotherView())
.environmentObject(viewModel)
}
else {
Text("Loading...")
}
}
.onAppear { viewModel.fetch() }
.onDisappear { viewModel.cancel() }
}
}
Thanks for your comments!
Thanks for the quick reply.
After some investigation I think our issue was that we used @StateObject
in a none correct way and it should now be solved!
Hi and thanks for a very nice library!
I am wondering if it would be possible to navigate between
two
andthree
withoutone
being rerendered?The way we use this is that the view model of
one
handles data fetching and is then passed totwo
(andthree
) via.environemntObject()
. But when navigating between thoseone
is recreated on all navigation steps as well.