In theory, this should be triggered every time this view appears. But in practice, it is only called when it is pushed on navigation stack, not when we return to it.
So if user goes to a bookmark in a bookmark list, unbookmark an item and go back to the bookmark list, onAppear is not called again and the list is not updated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
import SwiftUI
structBookmarksView: View{ let service: Service @Statevar items: [AnyItem] @EnvironmentObjectvar storeContainer: StoreContainer
var body: some View { List(items) { item in makeItemRow(item: item) .padding([.top, .bottom], 4) } .onAppear(perform: { self.items = storeContainer.bookmarks(service: service).map({ AnyItem(item: $0) }) }) } }
So instead of relying on UI state, we should rely on data state, by listening to onReceive and update our local @State