Registry / web-framework / react-recompose

react-recompose

JSON →
library0.33.0jsnpmunverified

react-recompose is a community-maintained fork of the original `recompose` library, designed to bring its utility belt for functional React components and higher-order components (HOCs) into compatibility with modern React versions. While the original `recompose` was officially deprecated by its author in 2018, advocating for React Hooks as its successor, this fork ensures its functionalities work with React 17 and 18. The current stable version is 0.33.0. Releases are primarily focused on dependency updates, security patches, and maintaining compatibility with the evolving React ecosystem, rather than introducing new features. It provides an HOC-based composition pattern for projects that predate Hooks or prefer this architectural style for component logic reuse.

npm install react-recompose
INSTALL
IMPORT
SIG · REACT-RECOMPOSE
R
react-recompose
web-frameworkjavascriptv0.33.0
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.

withState
import { withState } from 'recompose';
import { withState } from 'react-recompose';
Most users install this fork by aliasing 'react-recompose' to 'recompose' for seamless migration from the original library. If not aliased, use 'react-recompose'.
compose
import { compose } from 'recompose';
const { compose } = require('recompose');
ESM imports are standard for modern React applications. CommonJS 'require' style may lead to issues or require specific build configurations.
withHandlers
import { withHandlers } from 'recompose';
import withHandlers from 'recompose';
All utilities are named exports; there is no default export from the main package.

Demonstrates how to use `withState` and `compose` from `react-recompose` to manage local component state via a Higher-Order Component pattern.

import React from 'react'; import ReactDOM from 'react-dom/client'; import { withState, compose } from 'recompose'; // Define the props for the enhanced component interface CounterProps { counter: number; setCounter: (updater: (n: number) => number) => void; } // Create an enhancer using recompose's HOCs const enhance = compose<CounterProps, {}>( withState('counter', 'setCounter', 0) ); // Define the base functional component const CounterComponent: React.FC<CounterProps> = ({ counter, setCounter }) => ( <div> <h2>Recompose Counter Example</h2> <p>Current Count: {counter}</p> <button onClick={() => setCounter(n => n + 1)}>Increment</button> <button onClick={() => setCounter(n => n - 1)}>Decrement</button> </div> ); // Enhance the component const Counter = enhance(CounterComponent); // Render the enhanced component const rootElement = document.getElementById('root'); if (rootElement) { const root = ReactDOM.createRoot(rootElement); root.render( <React.StrictMode> <Counter /> </React.StrictMode> ); } else { console.error('Root element not found. Please ensure an element with id="root" exists in your HTML.'); } // Add a div#root to your HTML file to make this runnable. // Example: <div id="root"></div>
Debug
Known issues
deprecatedThe original 'recompose' library was officially deprecated by its author in 2018 in favor of React Hooks. While this 'react-recompose' fork provides maintenance, the HOC pattern it promotes is largely superseded by modern React's built-in Hooks for stateful logic and side effects.
fix
Consider migrating new component logic to React Hooks (e.g., `useState`, `useEffect`, `useReducer`) for better long-term maintainability and alignment with current React best practices.
affects: >=0.1.0
gotchaThis package is a fork of the original `recompose`. It is highly recommended to install it using a package manager alias (e.g., `yarn add recompose@npm:react-recompose` or `npm install recompose@npm:react-recompose`) to maintain consistent import paths (`import { ... } from 'recompose'`) and avoid breaking changes when migrating from the original.
fix
Install using `yarn add recompose@npm:react-recompose` (or `npm install recompose@npm:react-recompose`) and ensure your import statements use `from 'recompose'`. If not aliased, you must import from 'react-recompose'.
affects: >=0.1.0
breakingMinimum React version required is 16.2.0. Older React versions may not be compatible, and the library has been updated to support React 18 in recent versions.
fix
Ensure your project uses React 16.2.0 or higher. For React 18 compatibility, use `react-recompose` v0.33.0 or later.
affects: <0.33.0
gotchaPerformance optimizations discussed in early Recompose talks (e.g., Andrew Clark's React Europe talk) were removed from the original library in v0.26.0. This fork does not reintroduce them, so performance characteristics may differ from what was originally presented.
fix
Be aware that performance optimizations related to `shouldComponentUpdate` or pure components are not implicitly applied by all recompose helpers. Profile your application and implement `React.memo` or `useMemo`/`useCallback` where necessary with modern React.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
Attempting to use React Hooks within a component that is being managed by recompose HOCs in a way that violates Hooks rules, or mixing paradigms incorrectly.
fix
Ensure that components enhanced by recompose HOCs do not directly call Hooks at their top level unless they are themselves functional components that follow Hook rules. Prefer using either a pure HOC or pure Hook approach for a given component's logic.
TypeError: (0, _recompose.withState) is not a function
Incorrect import path for 'recompose' or the package was not installed with the recommended alias.
fix
Verify that `react-recompose` is installed as `recompose` via `yarn add recompose@npm:react-recompose` (or `npm install recompose@npm:react-recompose`), and that your import statements are `import { ... } from 'recompose';`.
Module not found: Can't resolve 'recompose' in 'path/to/your/component'
The package 'react-recompose' was installed without the alias, and your code expects to import from 'recompose'.
fix
Either install the package with the alias (`yarn add recompose@npm:react-recompose`) or change your import statements to `import { ... } from 'react-recompose';`.
npm ERR! ERESOLVE unable to resolve dependency tree
A mismatch between the required React peer dependency version of `react-recompose` and the React version installed in your project.
fix
Check the `peerDependencies` of `react-recompose` and ensure your project's `react` and `react-dom` versions fall within the specified range. Update React if necessary.
Upgrade
Version history
0.33.0latest on npm
Audit
Dependencies
reactrequiredCore runtime dependency for React components and HOCs.
Agent activity
4 hits · last 30 days
node
4
Resources
react-recompose — npm install react-recompose · libregistry