Redux-like state container in SwiftUI. Usage.

We can finish our repos search app that calls Github API asynchronously and fetches repositories matching a query.

typealias AppStore = Store<AppState, AppAction, AppEnvironment>

struct SearchContainerView: View {
@EnvironmentObject var s…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Sergey Leschev

We can finish our repos search app that calls Github API asynchronously and fetches repositories matching a query.

typealias AppStore = Store<AppState, AppAction, AppEnvironment>

struct SearchContainerView: View {
    @EnvironmentObject var store: AppStore
    @State private var query: String = "Swift"

    var body: some View {
        SearchView(
            query: $query,
            repos: store.state.searchResult,
            onCommit: fetch
        ).onAppear(perform: fetch)
    }

    private func fetch() {
        store.send(.search(query: query))
    }
}

struct SearchView : View {
    @Binding var query: String
    let repos: [Repo]
    let onCommit: () -> Void

    var body: some View {
        NavigationView {
            List {
                TextField("Type something", text: $query, onCommit: onCommit)

                if repos.isEmpty {
                    Text("Loading...")
                } else {
                    ForEach(repos) { repo in
                        RepoRow(repo: repo)
                    }
                }
            }.navigationBarTitle(Text("Search"))
        }
    }
}

We divide our screen into two views: Container View and Rendering View. Container View handles the actions and retrieves the needed piece of state from the global state. Rendering View accepts the data and renders it.

Contacts
I have a clear focus on time-to-market and don't prioritize technical debt. And I took part in the Pre-Sale/RFX activity as a System Architect, assessment efforts for Mobile (iOS-Swift, Android-Kotlin), Frontend (React-TypeScript) and Backend (NodeJS-.NET-PHP-Kafka-SQL-NoSQL). And I also formed the work of Pre-Sale as a CTO from Opportunity to Proposal via knowledge transfer to Successful Delivery.

🛩️ #startups #management #cto #swift #typescript #database
đź“§ Email: sergey.leschev@gmail.com
đź‘‹ LinkedIn: https://www.linkedin.com/in/sergeyleschev/
đź‘‹ LeetCode: https://leetcode.com/sergeyleschev/
đź‘‹ Twitter: https://twitter.com/sergeyleschev
đź‘‹ Github: https://github.com/sergeyleschev
🌎 Website: https://sergeyleschev.github.io


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Sergey Leschev


Print Share Comment Cite Upload Translate Updates
APA

Sergey Leschev | Sciencx (2023-02-11T16:03:50+00:00) Redux-like state container in SwiftUI. Usage.. Retrieved from https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-usage/

MLA
" » Redux-like state container in SwiftUI. Usage.." Sergey Leschev | Sciencx - Saturday February 11, 2023, https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-usage/
HARVARD
Sergey Leschev | Sciencx Saturday February 11, 2023 » Redux-like state container in SwiftUI. Usage.., viewed ,<https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-usage/>
VANCOUVER
Sergey Leschev | Sciencx - » Redux-like state container in SwiftUI. Usage.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-usage/
CHICAGO
" » Redux-like state container in SwiftUI. Usage.." Sergey Leschev | Sciencx - Accessed . https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-usage/
IEEE
" » Redux-like state container in SwiftUI. Usage.." Sergey Leschev | Sciencx [Online]. Available: https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-usage/. [Accessed: ]
rf:citation
» Redux-like state container in SwiftUI. Usage. | Sergey Leschev | Sciencx | https://www.scien.cx/2023/02/11/redux-like-state-container-in-swiftui-usage/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.