useSyncExternalStore
The useSyncExternalStore hook lets a component read and subscribe to a store that lives outside React — a browser API, a global singleton, a third-party state library. You give it a subscribe function (React calls it to be notified of changes) and a getSnapshot function (React calls it to read the current value). The optional getServerSnapshot supplies a value during server rendering so the markup matches on hydration. Below, two components subscribe to real browser state: your online/offline status and the viewport width.
Network status
Online
Subscribes to the browser’s online / offline events. Toggle your network (or DevTools offline mode) to watch it update.
Viewport width
—measuring…
Subscribes to the window resize event. Drag the browser edge to resize and this re-renders in sync.