Do stateless components in react improve performance?

in the process of learning, the teacher said that using stateless components can greatly improve performance, but recently, when reading the book "React Design patterns and Best practices", section 9.2.2 said that stateless components would not actually bring any state improvement. The teacher"s version is 16, and the book version is 15
. So the question comes: is JavaScript the best language in the world? (: angle)

Nov.30,2021

Don't say whether the performance of stateless components has improved,

even if you bind in render, it will not have much impact on performance, which can be confirmed by benchmark (it is generally believed that bind in render will have a greater impact on performance).

in addition, it is corrected that stateless components are not without lifecycles, and those without lifecycles should be functional components. So it doesn't make sense for stateless components to perform better,
guess what you're trying to say is that function components perform better. If you only compare a functional component with a non-functional component (there are no child components and parent components), there is no doubt that the performance is better (that's what your teacher may be talking about), but the actual project is used in combination, not necessarily. Therefore, non-functional components can use SCU to control whether the render, function component does not have such optimization space (which can be solved by internally maintaining a cache of LRU).

in short, not necessarily, depending on the situation


depends on how you use it.
in theory, stateless components have no doubt about performance improvement. Why?
the difference between stateless components and stateful components is that there is no React life cycle in stateless components. Stateless components do not have their own state, except the external props, so there will not be state changes in their own components that trigger the diff algorithm and will not re-render. (but external props changes still execute the diff algorithm.)
maybe that's the point that affects performance! To say that greatly improve performance, this point is not the same, but also exaggerated, this poor performance should not be perceived.

Even so, I personally think that the use of stateless components should not be compared by considering whether there is poor performance between them for the time being. You should choose who to use from how the code is written more reasonably. This point of performance can be put aside for the time being.

Menu