-
Notifications
You must be signed in to change notification settings - Fork 42
Open
Description
I think to be safe we should use @StateObject property wrapper instead of @ObservedObject for the ViewModels.
What I observed in my app when adopting this pattern is, that in some cases SwiftUI completely reinstantiates the whole View hierarchy. This happened in my app e.g. after dismissing a modally presented view again. With @ObservedObjectall viewModel states would be reset to .idle again. For some reason onAppear however is not called again which leaves us forever in the idle state. Using @StateObject will preserve the ViewModel state throughout these reinstantiation cycles
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels