You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: packages/use-subscription/README.md
+2-26
Original file line number
Diff line number
Diff line change
@@ -1,32 +1,8 @@
1
1
# use-subscription
2
2
3
-
React hook that safely manages subscriptions in concurrent mode.
3
+
React Hook for subscribing to external data sources.
4
4
5
-
This utility can be used for subscriptions to a single value that are typically only read in one place and may update frequently (e.g. a component that subscribes to a geolocation API to show a dot on a map).
6
-
7
-
## When should you NOT use this?
8
-
9
-
Most other cases have **better long-term solutions**:
10
-
* Redux/Flux stores should use the [context API](https://reactjs.org/docs/context.html) instead.
11
-
* I/O subscriptions (e.g. notifications) that update infrequently should use a mechanism like [`react-cache`](https://github.com/facebook/react/blob/main/packages/react-cache/README.md) instead.
12
-
* Complex libraries like Relay/Apollo should manage subscriptions manually with the same techniques which this library uses under the hood (as referenced [here](https://gist.github.com/bvaughn/d569177d70b50b58bff69c3c4a5353f3)) in a way that is most optimized for their library usage.
13
-
14
-
## Limitations in concurrent mode
15
-
16
-
`use-subscription` is safe to use in concurrent mode. However, [it achieves correctness by sometimes de-opting to synchronous mode](https://github.com/facebook/react/issues/13186#issuecomment-403959161), obviating the benefits of concurrent rendering. This is an inherent limitation of storing state outside of React's managed state queue and rendering in response to a change event.
17
-
18
-
The effect of de-opting to sync mode is that the main thread may periodically be blocked (in the case of CPU-bound work), and placeholders may appear earlier than desired (in the case of IO-bound work).
19
-
20
-
For **full compatibility** with concurrent rendering, including both **time-slicing** and **React Suspense**, the suggested longer-term solution is to move to one of the patterns described in the previous section.
21
-
22
-
## What types of subscriptions can this support?
23
-
24
-
This abstraction can handle a variety of subscription types, including:
25
-
* Event dispatchers like `HTMLInputElement`.
26
-
* Custom pub/sub components like Relay's `FragmentSpecResolver`.
27
-
* Observable types like RxJS `BehaviorSubject` and `ReplaySubject`. (Types like RxJS `Subject` or `Observable` are not supported, because they provide no way to read the "current" value after it has been emitted.)
28
-
29
-
Note that JavaScript promises are also **not supported** because they provide no way to synchronously read the "current" value.
5
+
**You may now migrate to [`use-sync-external-store`](https://www.npmjs.com/package/use-sync-external-store) directly instead, which has the same API as [`React.useSyncExternalStore`](https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore). The `use-subscription` package is now a thin wrapper over `use-sync-external-store` and will not be updated further.**
0 commit comments