← All notes

Subscribe to an external store with useSyncExternalStore

Answer: useSyncExternalStore is a React Hook that lets you subscribe to an external store. You pass a subscribe function, a getSnapshot function, and optionally getServerSnapshot. The Hook returns a snapshot of the store for this render.

The Hook arguments

subscribe should subscribe to the store and return an unsubscribe function. getSnapshot should return the current store value. getServerSnapshot is used when rendering on the server. React will re-render when the subscription signals a change and the snapshot is different.

Prefer this over an Effect

A useOnlineStatus example uses useSyncExternalStore with online and offline listeners. That is the built-in Hook for subscribing to an external store, instead of an Effect.

| useSyncExternalStore | arguments | |---|---| | subscribe | Subscribe and return an unsubscribe function | | getSnapshot | Return the current store value | | getServerSnapshot | Snapshot used when rendering on the server | | useOnlineStatus | Example that uses online and offline listeners |

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: React docs, useSyncExternalStore; React docs, You Might Not Need an Effect. CC-BY-4.0; CC-BY-4.0. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: React docs, useSyncExternalStore; React docs, You Might Not Need an Effect. CC-BY-4.0; CC-BY-4.0.

Cite this

Permanent ID: iil:note:6m7vswa1

iinventedlight. 2026. "Subscribe to an external store with useSyncExternalStore." iinventedlight Library, iil:note:6m7vswa1, version of 2026-11-19. https://iinventedlight.com/library/notes/react-usesyncexternalstore/. License: CC-BY-4.0.

@misc{iil_note_6m7vswa1,
  author = {{iinventedlight}},
  title = {{Subscribe to an external store with useSyncExternalStore}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-19},
  url = {https://iinventedlight.com/library/notes/react-usesyncexternalstore/},
  note = {Permanent ID iil:note:6m7vswa1. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/react-usesyncexternalstore.md.