0Pricing
React Academy · Lesson

The Problem with External Store Subscriptions

Understand tearing and why useState or useRef subscriptions to external stores are unsafe in concurrent React.

The Problem with External Store Subscriptions is a free React Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the React Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What an External Store Is

An external store is any source of state that lives outside the React tree, such as a Redux store, a browser API like matchMedia, or a plain module-level object with its own subscribe mechanism.

React does not own this state, so it must subscribe to changes and read snapshots to keep components in sync with whatever the store currently holds.

The Naive useState + useEffect Subscription

A common approach reads the store value into useState, then uses useEffect to subscribe and call setState whenever the store changes. On the surface this seems to keep the component current.

It works for simple synchronous rendering, but it has a subtle flaw that becomes visible once React renders concurrently and can pause or restart work mid-flight.

The Tearing Problem

Tearing happens when different parts of the UI display different values of the same store during a single render pass. Concurrent rendering can interrupt and resume work, and the store may change in between.

The result is an inconsistent screen where one component shows the old value and another shows the new one, an inconsistency that was effectively impossible before concurrent features.

Example: Tearing with Dark Mode Mid-Render

Imagine many components reading a theme store while React renders concurrently. If the user toggles dark mode partway through, components rendered before the toggle show the light theme and those after show dark.

You end up with a half-light, half-dark screen for a frame because the store value changed during a render that React did not treat atomically.

Why useEffect Is Too Late

Effects run after render is committed, so a useEffect-based subscription cannot guarantee the value read during render matches the store at commit time. The subscription fires too late to prevent an inconsistent paint.

By the time the effect resubscribes and updates state, the inconsistent frame may already have been shown to the user.

The Deprecated useMutableSource

An earlier experimental API called useMutableSource attempted to solve concurrent-safe external reads, but its API proved difficult to use correctly and was never released as stable.

The React team replaced it with a simpler, more ergonomic primitive that achieves the same consistency guarantees without the sharp edges.

useSyncExternalStore as the Solution

useSyncExternalStore is the official hook for subscribing to external stores in a concurrent-safe way. It coordinates with React so reads stay consistent across a render and components never tear.

It became the recommended primitive for library authors who need to bridge external state into React reliably under concurrent rendering.

Which Libraries Were Affected

State libraries that subscribe to external stores were directly affected, including Redux, MobX, and Valtio. Each needed to adopt the new primitive to remain safe once concurrent features shipped.

This is why their React bindings were updated to call useSyncExternalStore internally rather than relying on the older useState plus useEffect pattern.

Consistent Snapshot and Concurrent Safety

The hook guarantees that every component reading the store during a render sees the same snapshot, and it forces a synchronous re-render if the store changes in a way that would otherwise tear.

This combination of a consistent snapshot and concurrent safety is the core value the hook provides over hand-rolled subscriptions.

A Future-Proof Primitive

By using useSyncExternalStore, your subscriptions remain correct as React evolves its rendering model. You opt into the framework guarantees rather than reimplementing them imperfectly.

This makes it the durable, recommended way to connect any external source of truth to React components.

Quick Check: The Tearing Problem

Confirm what tearing means in concurrent rendering.

Recap: External Store Subscription Problems

External stores live outside React, and the naive useState plus useEffect subscription cannot prevent tearing once rendering is concurrent. Effects run too late to keep reads consistent within a render.

useSyncExternalStore replaces the abandoned useMutableSource and gives a consistent snapshot with concurrent safety. Libraries like Redux, MobX, and Valtio adopted it as the future-proof primitive for store subscriptions.

Frequently asked questions

Is the “The Problem with External Store Subscriptions” lesson free?

Yes — the full text of “The Problem with External Store Subscriptions” is free to read here on the web, and the React Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the React Academy course, upgrade to CoddyKit PRO.

What will I learn in “The Problem with External Store Subscriptions”?

Understand tearing and why useState or useRef subscriptions to external stores are unsafe in concurrent React. You practise React Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start React Academy?

No prior experience is required. React Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “The Problem with External Store Subscriptions” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this React Academy lesson?

Yes. Every React Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The Problem with External Store Subscriptions
  2. useSyncExternalStore API and Parameters
  3. Subscribing to Browser APIs
  4. Building a Custom Store with useSyncExternalStore
← Back to React Academy