Recompose: Branch: Support more than 2 HOCs?

Created on 14 Apr 2017  Â·  3Comments  Â·  Source: acdlite/recompose

I am trying to use branch to pick one of three HOCs to use. The current API signature for branch only accepts two HOCs. Is it possible to adapt this to compare amongst three, or n HOCs?

Most helpful comment

Or

compose(
  branch(test0, hocs0),
  branch(test1, hocs1),
  branch(p => !test1(p) && !test2(p), hocs2)
)

what you like more

All 3 comments

Create your own enhancer some kind of

const mySwitch = (fn, hocs0, hocs1, hocs2) => 
branch(
  p => fn(p) === 0, 
  hocs0,
  branch(
    p => fn(p) === 1, 
    hocs1,
    hocs2
  )
);

Or

compose(
  branch(test0, hocs0),
  branch(test1, hocs1),
  branch(p => !test1(p) && !test2(p), hocs2)
)

what you like more

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yellowfrogCN picture yellowfrogCN  Â·  3Comments

istarkov picture istarkov  Â·  3Comments

adrianmcli picture adrianmcli  Â·  3Comments

nemocurcic picture nemocurcic  Â·  3Comments

xialvjun picture xialvjun  Â·  4Comments