DEV Community

Discussion on: Merge High Order Component and Compound Pattern

Collapse
 
dcwither profile image
Devin Witherspoon

I think a more general solution for what you’re describing is hoist non react statics. It’ll do this work for you without passing in the compound component props you want (I haven’t tested this case since I’m reading on a phone) but I’ve used this in the past for similar scenarios, and it’s a staple of HOC development for this reason. Because at that point it really is easier and more clear of what’s going on to do:

AnalyticsCard.Header = Card.Header;
AnalyticsCard.Body = Card.Body;
Enter fullscreen mode Exit fullscreen mode

Instead of:

withAnalyticsCompound(Card, { Header, Body })
Enter fullscreen mode Exit fullscreen mode
Collapse
 
didof profile image
Francesco Di Donato

Hi Devin,
Thank you for sharing! I was not aware of the existence of this package and am really curious to understand how it works below.