New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

compose-component

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compose-component

A utility function for composing React components with children function. Inspired by redux `compose` / lodash `flowRight`.

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Compose Component Build Status PRs Welcome

A utility function for composing React components with children function. Inspired by redux compose / lodash flowRight.

Installation

$ npm i --save compose-component

Example

The following code will render A1,A2-B1,B2

import React from 'react';
import ReactDOM from 'react-dom';
import compose from 'compose-component';

const A = ({ children }) => <div>{children('A1', 'A2')}</div>;
const B = ({ children }) => <div>{children('B1', 'B2')}</div>;

const AB = compose(A, B);

// <AB>
//   {
//     (A, B) => <div>{`${A}-${B}`}</div>
//   }
// </AB>
//
// is equivalent to
//
// <A>
//   {(...A) => (
//     <B>
//       {
//         (...B) => <div>{`${A}-${B}`}</div>
//       }
//     </B>
//   )}
// <A>

ReactDOM.render(
  <AB>
    {(a1Args, [ b1, b2 ] /* destructured B args */) =>
      <span>{`${a1Args.join()}-${b1},${b2}`}</span>
    }
  </AB>,
  document.querySelector('#app')
);

API

compose(...Components: Array<ReactClass | ReactStatelessFunction>)

Returns: ReactClass with a children function, the parameters of which consist of arrays from each Component's children function parameter

License

MIT

FAQs

Package last updated on 26 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts