DEV Community

Cover image for Redux-like state container in SwiftUI. State composition.
Sergey Leschev
Sergey Leschev

Posted on • Updated on

Redux-like state container in SwiftUI. State composition.

It is very natural to store your app’s state as a single struct, but it simply can blow up as soon as you add more and more fields to your state struct. We can use state composition to solve this issue. Let’s take a look at the example.

struct AppState {
    var calendar: CalendarState
    var trends: TrendsState
    var settings: SettingState
Enter fullscreen mode Exit fullscreen mode

We divide our state into three dedicated pieces and compose them into AppState.

Redux provides a single source of truth, which eliminates tons of bugs produced by multiple states across the app. Best practices. Normalization and composition keep our app state simple and maintainable.

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:
👋 LinkedIn:
👋 LeetCode:
👋 Twitter:
👋 Github:
🌎 Website:
🌎 Reddit:
🌎 Quora:
🌎 Medium:

Top comments (0)