Why should ReactJS components act as pure functions?

the documentation says. All React components should act as pure functions in relation to their details. https://facebook.imtqy.com/react/docs/components-and-props.html but does not explain the true reason for this, why?

+4
source share
4 answers

I would say due to tracking component state changes. If it is not clean, it can cause side effects every time it is performed. Thus, it would be very difficult to find out what has changed and, moreover, how to respond to these changes.

, , . , - , .

0

, /, .

, : A B, A - B. A , - . B, , B A, .

- , , , B . , , . , , , , , . , . , .

https://facebook.imtqy.com/react/blog/2015/02/24/streamlining-react-elements.html#problem-mutating-props-you-dont-own

0

React , , render props state, render .

, , , React , DOM , . , . ? .

, - . , DOM , - , . React , , DOM, . , , , , , - .

Tree tree

h 8, f, h f, c, f c ...

- , React . , . c, a b. c f, e g. , , .

, , React , , , , , . React .

0

"" .

, , .

, , React, , .

Posting the answer here will be too much for the message and unnecessary because it has already explained to React Team. That is why I prefer to give you the source directly.

0
source

Source: https://habr.com/ru/post/1668549/


All Articles