In the previous articles in this series, we’ve looked at how SwiftUI and React Native manage state, pass it between views and components, and make it accessible throughout an application.
So far, we’ve covered:
- State vs useState – Managing local state.
- Binding vs Props – Sharing state between parent and child views.
- Environment vs Context – Making values accessible throughout a view hierarchy.
But what happens when an application becomes more complex?
What if we have multiple screens accessing the same data, several different operations modifying it, and business rules that need to be maintained consistently?
Simply making an object accessible throughout the application doesn’t necessarily solve the problem of managing that data.
This is where things get interesting. SwiftUI and React Native offer quite different approaches to organising application state.
Let’s take a look.
When applications grow
Let’s continue with our shopping application.
So far, we’ve managed to create a shopping cart, make it accessible throughout the application, and allow different views to add and remove products.
But imagine we now want to support:
- Changing product quantities.
- Applying discounts.
- Calculating totals.
- Managing checkout.
- Synchronising the cart with a server.
We need somewhere to centralise this functionality and ensure that changes to our data remain consistent.
There are several ways to approach this, but let’s look at what the two frameworks provide.

SwiftUI: Observable models
In our previous article, we introduced Apple’s Observation framework and the @Observable macro.
Let’s revisit our shopping cart example.
Rather than managing individual pieces of state across multiple views, we can create an observable model that owns the shopping cart data and the logic for modifying it.
import Observation
@Observable
class ShoppingCart {
var items: [Product] = []
var discount: Double = 0
var total: Double {
items.reduce(0) { $0 + $1.price }
* (1 - discount)
}
func add(_ product: Product) {
items.append(product)
}
func remove(_ product: Product) {
items.removeAll {
$0.id == product.id
}
}
func clear() {
items.removeAll()
}
}
Our model now has responsibility for both the data and the operations that modify it.
We can create an instance in our parent view:
struct ContentView: View {
@State private var cart = ShoppingCart()
var body: some View {
ShopView()
.environment(cart)
}
}
And other views can access it using @Environment, just as we explored in the previous article.
struct CartView: View {
@Environment(ShoppingCart.self)
private var cart
var body: some View {
VStack {
Text("Total: \(cart.total)")
Button("Empty Cart") {
cart.clear()
}
}
}
}
What’s particularly interesting here is that the model doesn’t need to know anything about the views using it.
It manages the data and provides methods for modifying it. SwiftUI’s Observation framework takes care of tracking which properties the views access and updating them when those properties change.
This is a fairly natural way to organise application state in SwiftUI.
We can also introduce additional observable models for other areas of our application, such as user preferences, authentication or application settings.
Of course, @Observable doesn’t prescribe a complete application architecture. We still need to decide where models are owned, how dependencies are distributed and where business logic belongs.
But it provides a useful foundation.
React Native: useReducer
React takes a somewhat different approach.
We’ve already looked at useState, but React also provides another hook that becomes particularly useful when state management gets more complicated: useReducer.
While useState is useful for managing individual pieces of state, useReducer allows us to centralise state transitions and describe how the state should change in response to different actions.
Let’s implement our shopping cart again.
First, we define the state and the actions that can modify it:
type CartState = {
items: Product[];
discount: number;
};
type CartAction =
| { type: 'add'; product: Product }
| { type: 'remove'; id: string }
| { type: 'discount'; value: number }
| { type: 'clear' };
We then create a reducer function:
function cartReducer(
state: CartState,
action: CartAction
): CartState {
switch (action.type) {
case 'add':
return {
...state,
items: [...state.items, action.product]
};
case 'remove':
return {
...state,
items: state.items.filter(
item => item.id !== action.id
)
};
case 'discount':
return {
...state,
discount: action.value
};
case 'clear':
return {
...state,
items: []
};
default:
return state;
}
}
Notice that we’re not directly modifying the existing state. Instead, the reducer returns a new state object representing the result of the requested action.
We can now use this reducer inside a component:
function CartProvider({ children }) {
const [state, dispatch] = useReducer(
cartReducer,
{
items: [],
discount: 0
}
);
return (
<CartContext.Provider value={{ state, dispatch }}>
{children}
</CartContext.Provider>
);
}
A component can access the state and dispatch actions through Context:
function CartView() {
const cart = useContext(CartContext);
if (!cart) {
throw new Error('CartProvider is missing');
}
const total = cart.state.items.reduce(
(sum, item) => sum + item.price,
0
) * (1 - cart.state.discount);
return (
<View>
<Text>Total: {total}</Text>
<Button
title="Empty Cart"
onPress={() => cart.dispatch({ type: 'clear' })}
/>
</View>
);
}
We now have a centralised place for managing our shopping cart state and the operations that modify it.
And, just as with our SwiftUI example, we can make this available throughout the application without passing it through every intermediate component.
Two different approaches
This is where I think the comparison becomes particularly interesting.
Both examples solve the same fundamental problem, but they organise state differently.
In SwiftUI, our observable model contains the data and the methods that modify it.
In React, our reducer defines the possible state transitions, and components dispatch actions to trigger them.
Let’s compare the two approaches.
| Concept | SwiftUI | React Native |
|---|---|---|
| State ownership | @State and model ownership | useReducer |
| Data model | @Observable class | State object |
| Modify state | Model methods | Dispatch actions |
| Define changes | Methods and model logic | Reducer function |
| Distribute state | @Environment | Context |
| Observe changes | Observation framework | React rendering and subscriptions |
There are some important differences worth highlighting.
1. How state changes are represented
With SwiftUI, we can encapsulate the logic for modifying our data inside methods on an observable model.
For example:
cart.add(product)
cart.remove(product)
cart.clear()
The model decides how those operations affect its internal state.
With React, we describe what we want to happen by dispatching an action:
dispatch({
type: 'add',
product
});
The reducer determines how the state changes in response.
This is a more explicit approach to state transitions.
Neither approach is inherently better. Observable models offer flexibility, while reducers provide a structured and predictable way of describing state changes.
2. How changes are observed
Another important difference is how the frameworks respond to changes.
SwiftUI’s Observation framework tracks which properties a view actually reads.
For example, if a view only reads cart.total, SwiftUI can track that dependency and update the view when relevant properties change.
React’s useReducer works differently.
When the reducer returns a new state, the component using it re-renders. If that state is distributed through Context, consuming components generally re-render when the provider’s value changes.
This can become important in larger applications where many components consume shared state.
React provides other mechanisms for optimising rendering, including splitting contexts and memoisation. External libraries can also provide more granular subscriptions.
3. How much structure do you need?
SwiftUI gives us considerable flexibility in how we organise our models.
We can use observable classes with methods, separate models into different areas of responsibility, and introduce additional architectural patterns as our application grows.
React’s useReducer encourages us to define state transitions explicitly.
This can be particularly useful when there are many different operations that modify the same data, because the possible transitions are all defined in one place.
However, useReducer doesn’t automatically provide a complete application architecture either. We still need to decide how to organise our state, where to place business logic and how to distribute dependencies.
Do we need third-party state management libraries?
So far, we’ve managed everything using functionality provided by the frameworks themselves.
But both ecosystems have additional options available.
In Swift, one example is The Composable Architecture (TCA), which provides a more structured approach to managing state, actions, effects and dependencies.
In React, popular alternatives include Zustand and Redux.
These libraries provide additional capabilities and architectural conventions, but they’re not prerequisites for managing application state.
For many applications, SwiftUI’s Observation framework or React’s combination of useReducer and Context will be perfectly adequate.
The important thing is to introduce additional complexity only when there’s a genuine need for it.
Different philosophies, similar goals
Looking back over this series, we’ve seen that SwiftUI and React Native approach state management from different perspectives.
SwiftUI provides an observable model-based approach, where models can own their data and encapsulate the logic for modifying it.
React provides hooks such as useState and useReducer, allowing developers to choose how they organise state and describe its transitions.
Both frameworks provide mechanisms for sharing that state throughout an application.
Neither approach is necessarily better. They simply reflect different design philosophies.
And perhaps that’s the most interesting thing about comparing these frameworks. They might look quite similar when we’re building simple interfaces, but as applications become more complex, their underlying approaches become much more apparent.
Wrapping up the series
We’ve now covered four interesting comparisons:
- State vs useState – Managing local state.
- Binding vs Props – Sharing state between parent and child views.
- Environment vs Context – Making values accessible throughout a view hierarchy.
- Observable Models vs Reducers – Managing more complex application state.
For Swift developers moving into React Native, understanding these differences is about more than learning a new syntax. It’s about understanding a different way of thinking about application architecture.
And for developers already familiar with both frameworks, hopefully these comparisons have highlighted a few interesting differences.
There are still plenty of other areas worth exploring. Layout, navigation, animations and lifecycle management all offer some fascinating comparisons.
More to come!
Leave a Reply