S
S
strannik_k2016-05-11 20:45:46
React
strannik_k, 2016-05-11 20:45:46

What are the advantages/disadvantages of HOC (Higher-order Components)?

I'm wondering - what advantages/disadvantages does HOC have?
Of particular interest is the information on the application of several different HOCs to one component:
1) is the order important in this case?
2) how to refer from one HOC to another (again, in case of applying several HOCs to one component) and do I need to worry about the order in this case?
I don't use them myself, so it's hard to judge them without experience of using them in real projects.
Thanks in advance for your reply!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2016-05-11
@strannik_k

Good evening.
Usually HOCs are made in such a way that the "order" is not important.
Refer from one HOC to another ... specify a specific task, it seems to me there is an easier way.
Benefits (Let's break down this video [EN]):
We described the "functionality" and added it with ease to our two components. Therefore, at least two excellent advantages were gained:
+ no code duplication
+ ease of adding "functionality"
Another good example is " Navigation Link" [RU] (the subsection is called - Navigation Link), again - we gave the functionality necessary for the component. If this functionality is useful somewhere else - we can arrange it.
Why the order is probably not important - because usually props are passed in the "take all properties" style (...this.props), where ... is the spread operator .
To sum it up:
by using HOC you are not "changing" the component it receives, but you are adding functionality in the process. Isn't it cool already?)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question