Re-RxJS
React bindings for RxJS
{story.title}
Main features
- 🌀 Truly Reactive
- ⚡️ Highly performant and free of memory-leaks
- 🔀 First class support for React Suspense and ready for Concurrent Mode
- ✂️ Decentralized and composable, thus enabling optimal code-splitting
- 🔬 Tiny and tree-shakeable
- 💪 Supports TypeScript
Table of Contents
- Installation
- API
- Core
- React Suspense Support
- Utils
- Examples
Installation
npm install re-rxjs
API
connectObservable
Accepts: An Observable.
Returns [1, 2]
-
A React Hook that yields the latest emitted value of the observable. If the Observable doesn't synchronously emit a value upon the first subscription, then the hook will leverage React Suspense while it's waiting for the first value.
-
A
sharedLatest
version of the observable that does not complete. It can be used for composing other streams that depend on it. The shared subscription is closed as soon as there are no subscribers to that observable.
connectFactoryObservable
Accepts: A factory function that returns an Observable.
Returns [1, 2]
-
A React Hook function with the same parameters as the factory function. This hook will yield the latest update from the observable returned from the factory function. If the Observable doesn't synchronously emit a value upon the first subscription, then the hook will leverage React Suspense while it's waiting for the first value.
-
A
sharedLatest
version of the observable returned by the factory function that does not complete. It can be used for composing other streams that depend on it. The shared subscription is closed as soon as there are no subscribers to that observable.
shareLatest
A RxJS pipeable operator which shares and replays the latest emitted value. It's the equivalent of:
The enhanced observables returned from connectObservable
and connectFactoryObservable
have been enhanced with this operator, but do not complete. Meaning that the latest
emitted value will be available until the refCount
drops to zero.
SUSPENSE
This is a special symbol that can be emitted from our observables to let the react hook know that there is a value on its way, and that we want to leverage React Suspense while we are waiting for that value.
suspend
A RxJS creation operator that prepends a SUSPENSE
on the source observable.
suspended
The pipeable version of suspend
switchMapSuspended
Like switchMap
but applying a startWith(SUSPENSE)
to the inner observable.
createInput
A couple examples are worth a thousand words:
or:
Examples
-
This is a contrived example based on this example from the React docs.
-
A search for Github repos that highlights the most recently updated one:
.thenresponse.json .thenrawData.items ?? ).map, ) const = connectObservable searchInput$.pipe switchMapSuspendedfindRepos, startWithnull, , const = connectObservable repos$.pipe mapArray.isArrayrepos && repos.length > 0 ? repos.reducecurrent.lastUpdate > winner.lastUpdate ? current : winner, : null, , , export default
Contributors ✨
Thanks goes to these wonderful people (emoji key):
Josep M Sobrepere 💻 🤔 🚧 ⚠️ 👀 📖 |
Víctor Oliva 🤔 👀 💻 ⚠️ 📖 |
Ed 🎨 |
Pierre Grimaud 📖 |
Bhavesh Desai 👀 📖 ⚠️ |
This project follows the all-contributors specification. Contributions of any kind welcome!