I have an @ObservableObject that I am passing down to a View, using:
TabView()
.environmentObject(stateManager)
In that view, I'm using:
@EnvironmentObject var stateManager: StateManager
I'm trying to pass some data down one view deeper into a View that will render that data in a list.
var body: some View {
ZStack {
Color("bgColor").ignoresSafeArea()
TabView {
DataListView(
items: stateManager.items
)
.tabItem {
Label("Items", systemImage: "list.bullet")
}
}
}
.onAppear{
print("Tab view has appeared!") // <= endless loop
}
}
In the DataListView (above), I have the following:
var items: [Item]
I have also tried using:
items: $stateManager.items
and
@Binding var items: [Item]
in the tabView and DataListView respectively
For some reason, probably due to my own ignorance, the Tabview renders endlessly.
I've also tried passing the entire state object and other combinations of arguments/parameters with the same result, but I'm bascially guessing at this point.
The items
being used are set prior to TabView render, and they are not being mutated at any point, so I'm unsure what's triggering the re-renders.
This issue only occurs when passing down to a "third" level. In other words, if I rendered the list in the TabView, there is no endless, re-render.
Again, there is a 99% probability that I'm not understanding how the data is supposed to flow, so any tips on passing this data down w/o an endless re-render would be most appreciated.
For the record, this is all happening with Xcode 13 beta 4.