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"?
- 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
1 Answer
Reset to default 7I 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条)