4 ms·
In terms of rendering this is actually correct. If you keep all your logic super high level, then your entire component tree will re-render often. Also, I thin
by ZephyrBlu 6y ago
In terms of rendering this is actually correct. If you keep all your logic super high level, then your entire component tree will re-render often.
Also, I think the author means that logic should as deep as it makes sense in the component tree which makes sense because then you can have better separation of concerns like he showed in his example.
- activitypea 6y agoThis is going against the actual established best practice of avoiding premature optimisations. React renders are crazy cheap, and when they start getting expensive, you can just chuck a PureComponent in there and `cut off` a whole subtree from unnecessary rerendering.
- ZephyrBlu 6y agoThere are definitely ways to mitigate excessive re-renders (Though they don't solve the problem of what happens when it actually needs to re-render), but there are also other reasons for wanting to push logic down the tree as far as possible like the one the author was conveying.
- zarathustreal 6y ago>If you keep all your logic super high level, then your entire component tree will re-render often. This is not true, especially if you're following _actual_ best practices and using e.g. React.memo() and immutable state updates. React is explicitly built around the idea that you don't need to re-render every part of the DOM on every state update.
- activitypea 6y agoRight, but you do have to re-render the React DOM, and for huge apps that can get expensive, at least in theory. I've yet to work on an app big enough where we have to reach for memo/PureComponent except for very specific cases e.g. a stock price ticker