Skip to content

Latest commit

 

History

History
33 lines (29 loc) · 696 Bytes

branch.md

File metadata and controls

33 lines (29 loc) · 696 Bytes

branch

Description

Accepts a test function and two higher-order components. The test function is passed the props from the owner. If it returns true, the left higher-order component is applied to BaseComponent; otherwise, the right higher-order component is applied.

API

branch(
  test  : (props : Object) => boolean,
  left  : Function,
  right : Function
) : Function

Example

import {
  branch,
  compose,
  defaultProps,
} from 'incompose';

const A = (props) => (
  <h1>counter is {props.counter}</h1>
);

export default compose(
  branch(
    (props) => props.value % 2 === 0,
    defaultProps({counter : 1}),
    defaultProps({counter : 2}),
  )
)(A);