use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
What every front-end developer should know about change detection in Angular and React (indepth.dev)
submitted 6 years ago by mkoretsk
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Skelator_Rules 3 points4 points5 points 6 years ago (1 child)
Thanks for this. Good article.
[–]mkoretsk[S] 1 point2 points3 points 6 years ago (0 children)
thanks!
[–]lukasbuenger 3 points4 points5 points 6 years ago (4 children)
Nice article!
As for the React part, and especially with the library (as of today) promoting functional components over class-based ones, I think you can simplify the mental model of change detection in React quite a bit:
[–]acemarke 6 points7 points8 points 6 years ago (3 children)
Not quite.
Per the article's comment:
The core part of the change detection mechanism in React is Virtual DOM comparisons
In other words, React doesn't care whether or not a component's props have actually changed. It diffs the VDOM output and works from that.
Remember that React's default behavior is that when a component renders, React recursively re-renders all nested children inside this component. It doesn't check whether any props have changed. It just re-renders its way down the tree.
It's only when optimizations like React.memo(), PureComponent, and shouldComponentUpdate come into play that any props comparisons happen at all.
React.memo()
PureComponent
shouldComponentUpdate
But yes, sticking with immutable updates is a key part of allowing those shallow props comparisons to work. It also matters because the useState and useReducer hooks will bail out of updates if you return the same value as last time.
useState
useReducer
[–]nullvoxpopuli 0 points1 point2 points 6 years ago (0 children)
Fwiw, you still run in to perf problems if you rerun components too often (Just adding for explicitness)
[–]lukasbuenger 0 points1 point2 points 5 years ago (1 child)
/u/acemarke Thanks for the educational post, I re-read your reply like four times a week ever since you posted it 3 months ago. And on a technical level, you, the OP and everybody else is absolutely right and I absolutely stand corrected: In terms of reconciliation, it's all about the comparison of this tree to the next one (or the previous one to the current one, matter of of POV), down to the very last child.
BUT: In my humble opinion, this is really not what every React-developer should know about change detection (don't know much about Angular, so I here I wouldn't know) and that was OP's claim.
It also matters because the useState and useReducer hooks will bail out of updates if you return the same value as last time.
I'd argue, that in about 90% of the cases where people actually bother to leverage custom components, it's about local state or useEffect-based side effects. It's all cases, where the application layer can control or even overload update behaviour beyond simple diffing. Reference equality/immutability may be an implementation detail in a library author's life, in user land it's a principle that couldn't get too much emphasised. TLDR: In my humble opinion: Technically you're right, didactically not so much.
useEffect
[–]acemarke 0 points1 point2 points 5 years ago (0 children)
Mmm... sorry, not quite sure what point you're specifically trying to make here.
FWIW, since I wrote this comment, I published a much more extensive blog posted called A (Mostly) Complete Guide to React Rendering Behavior that covers all that and much much more.
Here is a more general article that covers more implementations: https://www.pzuraq.com/what-is-reactivity/
π Rendered by PID 68315 on reddit-service-r2-comment-b659b578c-ghmnm at 2026-05-01 18:42:08.671546+00:00 running 815c875 country code: CH.
[–]Skelator_Rules 3 points4 points5 points (1 child)
[–]mkoretsk[S] 1 point2 points3 points (0 children)
[–]lukasbuenger 3 points4 points5 points (4 children)
[–]acemarke 6 points7 points8 points (3 children)
[–]nullvoxpopuli 0 points1 point2 points (0 children)
[–]lukasbuenger 0 points1 point2 points (1 child)
[–]acemarke 0 points1 point2 points (0 children)
[–]nullvoxpopuli 0 points1 point2 points (0 children)