DEV Community

Discussion on: Use hooks in class components with ease

Collapse
 
prince272 profile image
Prince Yaw Owusu

How do you inject more hooks into the class component?

Collapse
 
stroemdev profile image
Simon Ström • Edited

I assume you are using higher order components, then you can compose multiple higher order components into one component. There are several ready made utility functions for this. For example in lodash (flowRight) and compose if you are using redux.

You can check out this example I made using lodash flowRight and made two hooks available as HOC using my code example.
codesandbox.io/s/compose-higher-or...

Or you can wrap several higher order componens in each other, like this
withTodos(withUsers(App))
But I like the composing approach in the example for readability.

Hope it helps :-)