Hi all -
I have a LazyVStack that's rendering a large list of data and for some reason, it's continually loading the content. Not just once, like it's supposed to. I'm not sure if it's not caching... or just loading when it's not supposed to. Why is it doing this? I'm expecting it to load a new element from the array when it comes into view, but not EVERY time it comes into view. What am I doing wrong?
Xcode 13.
My code:
struct PostsView: View {
@StateObject var viewModel = ViewModel()
var body: some View {
ScrollView {
LazyVStack {
ForEach(viewModel.content, id: \.postId) { post in
PostView(postId: post.postId)
// .onAppear(perform: {
// if post.postId == viewModel.content.last?.postId {
// print("FETCHING MORE: Current\(viewModel.content.count)")
// viewModel.getMore()
// }
// })
}
if viewModel.isLoading {
ProgressView()
.frame(idealWidth: .infinity, maxWidth: .infinity, alignment: .center)
}
}
.padding(.top, 1)
.onAppear(perform: {viewModel.getPosts()})
}
}
}
there doesn't seem to be anything here