0

I understand how to avoid renders through memo, useMemo, and useCallback, my question is not about that. Rather:

  1. Why does React, by default, choose to rerender children that don’t receive props, when the parent updates? It seems like bad separation of responsibility and unnecessary computation. It feels like the child rerender should be left to the jurisdiction of the child.

  2. Why does React, by default, choose to rerender children whose props haven’t changed by value? Essentially I’m asking why aren’t useCallback and useMemo built in by default. Again it seems like an odd design decision.

I am not asking for solutions to make performant React code, rather trying to understand the design decisions. Kindly note most similar questions just have answers where people mention to use the 3 memoize functions. I would just like to understand why React was built the way it was. Thanks!

713sean
  • 313
  • 11
  • They can prevent re-rendering children in certain cases. Please reread – 713sean Jan 02 '23 at 21:58
  • Are you looking for [Why does React re-render children when the parent changes?](https://stackoverflow.com/questions/65643866/why-does-react-re-render-children-when-the-parent-changes) – ggorlen Jan 02 '23 at 22:03
  • No, that post seems to only tell how to avoid it, I’m asking for the design decision separate from the diffing alg – 713sean Jan 02 '23 at 22:15
  • Well indeed if parent changes, all the direct children are re-rendered but the re-rendering doesn't necessarily changes the actual DOM , thats how React works, and when React was create React was class base component, which mean we mostly use pure component approch, so no re-rendering issue, but now with functional component other tool was made to address those issue (like you mention with Memo) – ShueiYang Jan 02 '23 at 22:38
  • Yes, but why do we even rerender the VDOM? – 713sean Jan 03 '23 at 00:27

0 Answers0