-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Correct me if Im misunderstanding something but this plugin shouldn't be worried about shouldComponentUpdate() returning false in line 37 of the component for it's children. This just prevents it's child nodes line 15 of the component from rerender and has no bearing on the Parent <Target> node itself right?
Take the following:
<App>
<div>
<MyBody>
<Target>
<UsersWrappedContent>
<MoreUserChangingContent/>
</UsersWrappedContent>
</Target>
</MyBody>
</div>
</App>According to the react docs React will replace the first node that it detects change.
React will tear down the old tree and build the new tree from scratch.
When tearing down a tree, old DOM nodes are destroyed.
<App> <----So it will check the root node. Has it been updated? No. Next!
<div> <---- Has it been updated? No. Next!
<MyBody> <---- This one? No. Next!
<Target> <---- This one? Yes. so just replace it's children while maintaining state across render
<UsersWrappedContent>
<MoreUserChangingContent/>
</UsersWrappedContent>
</Target>
</MyBody>
</div>
</App>Further:
When a component updates, the instance stays the same, so that state is maintained across renders. React updates the props of the underlying component instance to match the new element
Any components below the root will also get unmounted and have their state destroyed.
So if the component is maintained across renders is there anything i'm missing as to why you're setting shouldComponentUpdate() like that?
(I also made this example pen to illustrate what shouldComponentUpdate() is doing if it helps)