Skip to content
fa
Search Frontend Atlas
Search questions and concepts across the handbook.
Frameworks & UI Architectureintermediate9 min read

Why is duplicating derived state in a UI component risky?

Distinguish source state from computed values and identify synchronization bugs.

Useful prerequisites

Suppose a page stores a list of products and also stores the number of products in that list. Every time the list changes, the count must change too. If one update is missed, the UI contradicts itself. Derived state avoids this kind of drift by calculating values from the data they describe.

Suppose a page stores a list of products and also stores the number of products in that list. Every time the list changes, the count must change too. If one update is missed, the UI contradicts itself. Derived state avoids this kind of drift by calculating values from the data they describe.

The quick version

Store the minimal state needed to represent user intent; derive values that can be computed from it. Duplicating derived data creates multiple sources of truth that must be kept synchronized.

Build the mental model

If filteredItems is fully determined by items and query, storing it independently creates invalid combinations. Memoization is a performance optimization, not a correctness requirement; introduce it only when measurement or identity semantics justify it.

See it in code

const visibleItems = items.filter((item) => item.name.includes(query));

Where it gets tricky

Effects that copy one state variable into another often create a one-render lag and ordering problems. Derive synchronously when possible. If a value is expensive, memoize based on its real dependencies; if it represents a user decision, store that decision rather than a derived projection. Async resources need explicit pending, success, and error states.

A common misunderstanding

“Avoid derived state” does not mean “never cache.” It means cache only with an explicit invalidation and consistency model.

What this changes in an application

This principle reduces effect chains, stale UI, race conditions, and unnecessary state transitions.

Questions worth exploring next

  • When is a reducer useful?
  • How would you model an async resource state without impossible combinations?

References and next steps

Explore next