javascript - Why and how does Object.assign increase app performance in React? - Stack Overflow

I am reading the Facebook tutorial for React. About 40% of the way through, there's a section call

I am reading the Facebook tutorial for React. About 40% of the way through, there's a section called Why Immutability is Important where they state (regarding the importance of immutability):

The end result is the same but by not mutating (or changing the underlying data) directly we now have an added benefit that can help us increase ponent and overall application performance.

My question is: why/how? That is, in React, specifically why/how does immutability (using Object.assign(...), etc.) "help increase...overall application performance"?

I am reading the Facebook tutorial for React. About 40% of the way through, there's a section called Why Immutability is Important where they state (regarding the importance of immutability):

The end result is the same but by not mutating (or changing the underlying data) directly we now have an added benefit that can help us increase ponent and overall application performance.

My question is: why/how? That is, in React, specifically why/how does immutability (using Object.assign(...), etc.) "help increase...overall application performance"?

Share Improve this question asked Jan 3, 2017 at 12:18 smeebsmeeb 29.7k71 gold badges274 silver badges474 bronze badges 1
  • The subsection titled Tracking Changes seems to explain it quite well IMO - is it unclear, or are you asking for a more technically detailed explanation? – UnholySheep Commented Jan 3, 2017 at 12:22
Add a ment  | 

1 Answer 1

Reset to default 7

I think that it is easier to understand with arrays:

Imagine that you have an array, containing many, many entries. You replace one entry with another - to see if anything changed react has to loop through the whole array.

Now, imagine that everytime you make some changes you create new array - then the only thing react has to do is to pare references

Object.assign does the same - instead of changing existing object, you create a new one, so that react can detect changes simply by paring references

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744715354a4589585.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信