Using Container Views with Redux-like state container
Tags: swift, ios, mobile, programming
Published: 2023-03-12 12:49:36

During my transition from multiple stores 

- [Basics](https://dev.to/sergeyleschev/redux-like-state-container-in-swiftui-basics-single-source-of-truth-2lpc)
- [Reducer and Actions](https://dev.to/sergeyleschev/redux-like-state-container-in-swiftui-basics-reducer-and-actions-flg)
- [Unidirectional flow](https://dev.to/sergeyleschev/redux-like-state-container-in-swiftui-basics-unidirectional-flow-3f2p)
- [Side effects](https://dev.to/sergeyleschev/redux-like-state-container-in-swiftui-side-effects-3l23)
- [Usage](https://dev.to/sergeyleschev/redux-like-state-container-in-swiftui-usage-k1i)
- [State normalization](https://dev.to/sergeyleschev/redux-like-state-container-in-swiftui-state-normalization-108o)
- [State composition](https://dev.to/sergeyleschev/redux-like-state-container-in-swiftui-state-composition-57e5)
- [Reducer composition](https://dev.to/sergeyleschev/redux-like-state-container-in-swiftui-reducer-composition-3j0m)
- [Derived stores](https://dev.to/sergeyleschev/redux-like-state-container-in-swiftui-derived-stores-2d62)

to a single source of truth, I realize that [Container Views](https://dev.to/sergeyleschev/redux-like-state-container-in-swiftui-container-views-a35) 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.

```swift
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://linkedin.com/in/sergeyleschev/
👋 LeetCode: https://leetcode.com/sergeyleschev/
👋 Twitter: https://twitter.com/sergeyleschev
👋 Github: https://github.com/sergeyleschev
🌎 Website: https://sergeyleschev.github.io
🌎 Reddit: https://reddit.com/user/sergeyleschev
🌎 Quora: https://quora.com/sergey-leschev
🌎 Medium: https://medium.com/@sergeyleschev