4 ms·
So uh, HOC's are basically monads. Right?
by Double_Cast 10y ago
So uh, HOC's are basically monads. Right?
- danabramov 10y agoI think the intuition might be a little bit related but AFAIK monad is a very specific thing (can “lift” something and map functions over it, or at least that’s what I remember from a monad tutorial), and HOCs are different (they just wrap components). “Decorator” might be a closer pattern. I would say HOC is more like a regular higher order function... which is why it’s called this way. :P
- smadge 10y agoI agree, a "higher order component" just isn't a monad. A HOC is just good old fashioned object composition. I think you are right to call it the decorator pattern. It annoys me how React ,and in general the entire javascript ecosystem, reinvents the wheel, then gives their invention another name.
- danabramov 10y agoIt’s not quite object composition though. We are not forwarding any method calls or containing the instances. HOCs are much closer to functional composition than to object composition.
- pka 10y agoNo no, just higher order functions. They don't have join and return.