Pure ReactJS Components

Dan Abramov says

... a component is clean if it is guaranteed to return the same result with the same details and condition.

Therefore, if the component is provided with the same details, the same output will always be returned. This is clear.

Then he says

pure components ... do not rely on deep mutations in requisites or states, therefore their rendering performance can be optimized by fine comparison in their hook shouldComponentUpdate()

But this means that I can provide a clean component with the same props, but with a difference deeper inside the specified props, and the component will display the same, but for different (although deep differences) props. This means that this restriction does not apply.

I declare the component as extends PureComponentreally saying ReactJS "I know what I am doing. I guarantee that I use an immutable state. Therefore, you only need to perform small comparisons of details in shouldComponentUpdate"?

Finally, it PureComponentprovides a default method by default shouldComponentUpdate- apparently this can be overridden by what you want (even a deep comparison)?

+4
source share
2 answers

Declares the component as an extension of PureComponent, really saying ReactJS "I know what I am doing. I guarantee that I use an immutable state. Therefore, you only need to perform the small details in shouldComponentUpdate"?

Yes

, PureComponents toComponentUpdate - -, , ( )?

. React , . Component .

+1

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


All Articles