Skip to content

useSyncExternalStore

In one line

useSyncExternalStore connects React to external state (Redux, Zustand) with concurrent-safe subscriptions.

In simple words

useSyncExternalStore (React 18) is the official way to read from external stores (Redux, Zustand, browser APIs) in a way that's safe with concurrent rendering.

It takes three arguments:

  1. subscribe — register a callback that fires on store changes
  2. getSnapshot — read the current value (must return the same reference if unchanged)
  3. getServerSnapshot (optional) — read value during SSR

Without this, external store reads can cause "tearing" in concurrent mode — different parts of the UI showing different values from the same store. This hook prevents that.

Example

jsx
import { useSyncExternalStore } from "react";

// Simple external store
let count = 0;
const listeners = new Set();
const store = {
  subscribe(cb) { listeners.add(cb); return () => listeners.delete(cb); },
  getSnapshot() { return count; },
  increment() { count++; listeners.forEach(cb => cb()); },
};

function Counter() {
  const value = useSyncExternalStore(
    store.subscribe, store.getSnapshot
  );
  return <button onClick={store.increment}>Count: {value}</button>;
}

useSyncExternalStore safely connects React to external state. The store notifies React of changes via subscribe, and React reads via getSnapshot.

Common confusions

  • Confused with: useSelector

    The difference: useSelector is a Redux-specific hook. useSyncExternalStore is the React built-in that Redux/Zustand now use under the hood. It's the low-level primitive for any external store, not specific to any state library.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary