Registry / web-framework / react-props-stream

react-props-stream

JSON →
library1.0.1jsnpmunverified

react-props-stream is a utility library designed to bridge RxJS reactive streams with React components. It offers three primary mechanisms: `withPropsStream` (a Higher-Order Component), `streamingComponent` (a functional component constructor), and `WithObservable` (a render prop component), all enabling the declaration of component props or children based on Observable streams. The current stable version is 1.0.1, which introduced updates for TypeScript 4 and ES Module exports. While not frequently updated, it provides a stable and specialized approach for managing complex, asynchronous component logic using RxJS operators. Its key differentiation lies in providing a declarative, stream-based API for React, conceptually similar to patterns found in `recompose` but with a direct and focused integration with the RxJS ecosystem. It allows for efficient handling of data fetching, derived state, and animated values without relying solely on React's internal state management for all asynchronous operations.

npm install react-props-stream
INSTALL
IMPORT
SIG · REACT-PROPS-STREAM
R
react-props-stream
web-frameworkjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

withPropsStream
import { withPropsStream } from 'react-props-stream'
const { withPropsStream } = require('react-props-stream')
ESM-only since v1.0.1. `withPropsStream` is a Higher-Order Component to connect an Observable to component props.
streamingComponent
import { streamingComponent } from 'react-props-stream'
const streamingComponent = require('react-props-stream').streamingComponent
ESM-only since v1.0.1. `streamingComponent` creates a React component from an Observable of React elements.
WithObservable
import { WithObservable } from 'react-props-stream'
const WithObservable = require('react-props-stream').WithObservable
ESM-only since v1.0.1. `WithObservable` is a render prop component that subscribes to an observable.
createEventHandler
import { createEventHandler } from 'react-props-stream'
const createEventHandler = require('react-props-stream').createEventHandler
ESM-only since v1.0.1. Used to create an event stream from React event handlers.

Demonstrates `withPropsStream` to create a component whose props (an ever-increasing counter) are driven by an RxJS `timer` observable, updating every second.

import React from 'react'; import ReactDOM from 'react-dom/client'; import { withPropsStream } from 'react-props-stream'; import { timer } from 'rxjs'; import { map } from 'rxjs/operators'; // Create an observable that emits an object { number: n } every second const numbers$ = timer(0, 1000).pipe( map(n => ({ number: n })) ); // Define a simple functional component that displays a number prop const DisplayNumber = (props: { number: number }) => ( <div>The number is {props.number}</div> ); // Wrap the component with withPropsStream to inject props from the observable const MyStreamingComponent = withPropsStream( numbers$, DisplayNumber ); // Render the streaming component into the DOM const rootElement = document.getElementById('root'); if (rootElement) { const root = ReactDOM.createRoot(rootElement); root.render( <React.StrictMode> <MyStreamingComponent /> </React.StrictMode> ); } // To run this, ensure you have an HTML file with `<div id="root"></div>`
Debug
Known issues
breakingThe package transitioned to ES Modules (ESM) exclusively since version 1.0.1. Projects configured for CommonJS (CJS) will encounter import errors.
fix
Migrate your project to use ES Modules, or if absolutely necessary, use dynamic `import()` for `react-props-stream` to load it asynchronously in a CJS context.
affects: >=1.0.1
breakingThe dependency on `recompose` was removed in v1.0.1. While `react-props-stream` was inspired by `recompose`, projects implicitly relying on `recompose` being a transitive dependency may experience issues.
fix
Ensure `recompose` is explicitly installed in your project if still needed. Review your `react-props-stream` usage for any assumptions based on `recompose`'s presence or API.
affects: >=1.0.1
gotchaThe library peer-depends on `rxjs@^6`. Using newer versions of RxJS (v7, v8+) might introduce compatibility issues or require adapting import paths and operators, as RxJS has undergone breaking changes across major versions.
fix
Adhere strictly to `rxjs@^6` for full compatibility. If using newer RxJS versions, carefully review their migration guides and adapt your RxJS code accordingly.
affects: >=1.0.0
gotchaThe library requires React version `'>=16'`. Using older React versions will result in runtime errors.
fix
Ensure your project is using React 16 or a newer version (e.g., React 17 or 18).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , rxjs_1.timer) is not a function
Mismatch in RxJS version, or incorrect import path for RxJS operators/creators (e.g., trying to import `timer` from `rxjs/operators` instead of `rxjs`).
fix
Verify that `rxjs@^6` is installed and that imports follow the RxJS v6 pattern: `import { timer } from 'rxjs'` for creation functions and `import { map } from 'rxjs/operators'` for operators.
Error [ERR_REQUIRE_ESM]: require() of ES Module ...react-props-stream/dist/index.js from ... is not supported.
Attempting to import `react-props-stream` using CommonJS `require()` syntax in a Node.js or bundler environment that expects ES Modules.
fix
Configure your project to use ES Modules (e.g., set `"type": "module"` in `package.json`) or switch to ES Module import syntax: `import { withPropsStream } from 'react-props-stream'`.
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Passing an invalid component type to `withPropsStream` or `streamingComponent`, or incorrect usage of the HOC where the wrapped component is not a valid React element.
fix
Ensure the argument provided as the `BaseComponent` to `withPropsStream` or the component returned by `streamingComponent`'s observable is a valid React functional or class component.
Invariant Violation: Objects are not valid as a React child (found: object with keys {number}). If you meant to render a collection of children, use an array instead.
When using the `WithObservable` component, the render prop function is trying to directly render an object emitted by the observable rather than a primitive value or a React element.
fix
Ensure the render prop function of `WithObservable` explicitly extracts and renders a valid React child (e.g., a string, number, or React element) from the observable's emission: `<WithObservable observable={num$} >{({ number }) => <div>{number}</div>}</WithObservable>`.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
rxjsrequiredCore reactive programming library for streams.
reactrequiredRequired for building user interfaces.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
2
Amazon
1
Resources
react-props-stream — npm install react-props-stream · libregistry