Until now we were used to Flux flow where data entered into the component through props. So you could look at the Props signature and see what is the component requirements.
Hooks are an amazing feature, but as we transition to them I find that they provide another entrance for dependencies which is harder to manage since you have to look at the actual component code to see it.
Of course, we can use Hooks only in container components, but I feel that some of their main selling points are their ability to reduce nesting and HOC.
What are the best practices (currently) for deciding which component should use a hook and which should use render props?
No, they do not.
Though rumored to do so in the community, classes are not being replaced in React. Rather, Hooks can work more efficiently with the same React concepts, allowing users to access props, state, context, refs, and lifecycle with a functional approach. It is not required to refactor class components into functional ones.
Hooks make React so much better because you have simpler code that implements similar functionalities faster and more effectively. You can also implement React state and lifecycle methods without writing classes.
Hooks and HOCs are different programmings models, and comparing them will seem to be as comparing oranges and apples.
TL;DR
As a rule of thumb, I use HOCs when I want a conditional rendering of components (if condition: render A, else render B), otherwise, I use hooks. That's only my opinion.
HOCs Pros
HOCs Cons
x
.HOCs Pro & Con both
Hooks Pros
Hooks Cons
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With