Get started with recompose CDN

MIT licensed

Modularly compose complex React function component behaviors with higher-order components and decorators .

Tags:
  • react
  • higher-order
  • components
  • microcomponentization
  • toolkit
  • utilities
  • composition

Stable version

Copied!

How to start using recompose CDN


import React from 'react';
import { compose, withProps, withState } from 'recompose';

const EnhancedComponent = (props) => {
  const [count, setCount] = React.useState(0);

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
      {props.someProp && <p>Some prop is true</p>}
    </div>
  );
};

const withCounter = withState('count', 'setCount');
const withConditionalRender = withProps({ someProp: true });

const EnhancedComponentWithRecompose = compose(withCounter, withConditionalRender)(EnhancedComponent);

export default EnhancedComponentWithRecompose;

All versions