Using Container Views with Redux-like state container

During my transition from multiple stores

Basics
Reducer and Actions
Unidirectional flow
Side effects
Usage
State normalization
State composition
Reducer composition
Derived stores

to a single source of truth, I realize that Container Views play a…


This content originally appeared on DEV Community and was authored by Sergey Leschev

During my transition from multiple stores

to a single source of truth, I realize that Container Views play a significant role in this approach. I mainly use them for sending actions to the store and mapping the global app state to Rendering View properties. Container Views perfectly fit into my current app architecture. Let’s take a look at the example.

import SwiftUI

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

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

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

struct SearchView: View {
    @Binding var query: String

    let repos: [Repo]
    let onCommit: () -> Void

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

As you can see in the example above, Container View helps us to keep Rendering Views small and independent.

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-03-12T12:49:36+00:00) Using Container Views with Redux-like state container. Retrieved from https://www.scien.cx/2023/03/12/using-container-views-with-redux-like-state-container/

MLA
" » Using Container Views with Redux-like state container." Sergey Leschev | Sciencx - Sunday March 12, 2023, https://www.scien.cx/2023/03/12/using-container-views-with-redux-like-state-container/
HARVARD
Sergey Leschev | Sciencx Sunday March 12, 2023 » Using Container Views with Redux-like state container., viewed ,<https://www.scien.cx/2023/03/12/using-container-views-with-redux-like-state-container/>
VANCOUVER
Sergey Leschev | Sciencx - » Using Container Views with Redux-like state container. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/03/12/using-container-views-with-redux-like-state-container/
CHICAGO
" » Using Container Views with Redux-like state container." Sergey Leschev | Sciencx - Accessed . https://www.scien.cx/2023/03/12/using-container-views-with-redux-like-state-container/
IEEE
" » Using Container Views with Redux-like state container." Sergey Leschev | Sciencx [Online]. Available: https://www.scien.cx/2023/03/12/using-container-views-with-redux-like-state-container/. [Accessed: ]
rf:citation
» Using Container Views with Redux-like state container | Sergey Leschev | Sciencx | https://www.scien.cx/2023/03/12/using-container-views-with-redux-like-state-container/ |

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.