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
- id: C1 claim: useSyncExternalStore is a Hook that lets you subscribe to an external store. source: S1 evidence: "subscribe to an external store"
- id: C2 claim: It takes subscribe, getSnapshot, and an optional getServerSnapshot. source: S1 evidence: "subscribe , getSnapshot , getServerSnapshot"
- id: C3 claim: The learning guide uses it as a built-in Hook for subscribing to an external store, such as online status. source: S2 evidence: "Subscribing to an external store with a built-in Hook"
Sources
- [S1] useSyncExternalStore. React docs. https://react.dev/reference/react/useSyncExternalStore . License: CC-BY-4.0. Accessed 2026-11-19.
- [S2] You Might Not Need an Effect. React docs. https://react.dev/learn/you-might-not-need-an-effect . License: CC-BY-4.0. Accessed 2026-11-19.
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
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.},
}
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.
- react-usesyncexternalstore.table.json (table; CC-BY-4.0)
- react-usesyncexternalstore.schema.json (schema; CC-BY-4.0)
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.