Derived State and Automatic Recalculation
You'll learn when automatically updating computed values justify the overhead of reactive architecture.
What Is Derived State?
Derived state is data calculated from other data sources. Think of it like a spreadsheet formula: when cells A1 and B1 change, cell C1 (which contains =A1+B1) updates automatically. In JavaScript, you might have a fullName derived from firstName and lastName, or a totalPrice computed from cartItems.
The Manual Approach vs Reactive
Without reactivity, you manually recalculate derived values whenever source data changes. This works fine for simple cases but becomes error-prone with:
- Multiple dependencies:
totalPricemight depend onitems,taxRate, anddiscountCode - Deep dependency chains: A changes B, B changes C, C changes D
- Many consumers: Ten different UI elements need the same derived value
When Reactivity Justifies the Overhead
Reactive patterns (signals, observables, computed values) shine when:
- Frequent recalculation: Values change often and need immediate updates
- Complex dependency graphs: Multiple derived values depend on each other
- Unknown consumers: You don't know upfront what will need the derived data
- Consistency guarantees: All derived values must update atomically
If you have a single derived value with one dependency that changes rarely, manual recalculation is simpler. But when your shopping cart's total depends on items, shipping, tax, discount codes, and membership status—and changes trigger UI updates in five places—reactive patterns prevent bugs and simplify maintenance.
Key Takeaway: Use reactive derived state when you have complex dependency chains, frequent updates, or multiple consumers that must stay synchronized; stick with manual recalculation for simple, isolated cases.