Created
August 4, 2024 11:04
-
-
Save gaeng2y/49e01cc718282ee8fdbfbf6e2354d027 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct ContentView: View { | |
| @ObservedObject var store = Store.shared | |
| @State private var newItemText: String = "" | |
| var body: some View { | |
| VStack { | |
| TextField("New Item", text: $newItemText) | |
| Button(action: { | |
| Dispatcher.shared.dispatch(action: .addTodoItem(text: newItemText)) | |
| newItemText = "" | |
| }) { | |
| Text("Add Item") | |
| } | |
| List { | |
| ForEach(store.todoItems.indices, id: \.self) { index in | |
| Text(store.todoItems[index]) | |
| .onTapGesture { | |
| Dispatcher.shared.dispatch(action: .removeTodoItem(index: index)) | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment