Re:Designing simpler React components
by CGamesPlay on Saturday March 26, 2016 @09:52PM
(#11368465)
How does all of the cloning affect performance? It feels wasteful to create these short-lived components that are explicitly discarded for slightly modified ones, but is that actually a problem?
[ Parent
| on HN ]
I'm not sure of the exact logic it uses, but it appears to me that when React finds a new component in place of an old one of the same class, it just changes the props on the old component (and calls componentWillReceiveProps) which bypasses some of the lifecycle calls.
Also, I believe Chrome and Firefox (and hopefully other) garbage collectors use a generational algorithm which makes it very cheap to throw away short-lived objects.
Of course it's more efficient just to mutate state, but these factors and other optimizations should mitigate the added cost and I think for most applications, the wasted cycles are not going to be much concern.