Skip to content

Instantly share code, notes, and snippets.

@hmlongco
Last active December 20, 2021 17:15
Show Gist options
  • Save hmlongco/e12acaa6799eeee5ea750f05b4e3fc6d to your computer and use it in GitHub Desktop.
Save hmlongco/e12acaa6799eeee5ea750f05b4e3fc6d to your computer and use it in GitHub Desktop.
LoadingView state dispatch
struct LoadingView: View {
@StateObject var viewModel = ViewModel()
var body: some View {
switch viewModel.state {
case .initial, .loading:
ProgressView()
.onAppear(perform: viewModel.load)
case .empty(let message):
Text(message)
.foregroundColor(.secondaryBrand)
case .error(let error):
Text(error)
.foregroundColor(.error)
case .loaded(let items):
ContentItemList(items: items)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment