Tech
Bridging RxJS BehaviorSubject and React with useSyncExternalStore
If you keep shared, mutable state in an RxJS BehaviorSubject — a WebSocket connection status, a design-system theme, a cache shared between routed pages — you eventually need to read that state from a React component and re-render when it changes. For years the answer was a hand-rolled useEffect + useState subscription, react-rxjs , or useObservable from some utility library.
Since React 18 there's a built-in, purpose-built hook for exactly this: useSyncExternalStore . It's the same...
Read the full discussion on Dev.to
This article was aggregated from Dev.to. Click to join the conversation.
View on Dev.to