|
|
|
|
|
by skydhash
321 days ago
|
|
The parent is the source of truth for the children nodes. Which means don't send anything down that you don't intend to be stable. As the children will (and should) treat it as gospel. That also means that the root component is god for the whole view. Most source of bugs happens when people ignore this simple fact. Input start from the root and get transformed along the way. Each node can bring things from external, but it should be treated careful as the children down won't care. It's all props to them. Which also means don't create new objects out of the blue to pass down. When you need to do so, memoize. As the only reason you need to do so is because you want: - to join two or more props or local state variables - or to transform the value of a prop or a local state variable (in an immutable fashion, as it should be). - or both. |
|
1. Enforce that you're always memoizing everywhere always
2. Memoize every new function and object (and array) and pray everyone else does too
#1 is pretty miserable, #2 is almost always guaranteed to fail.
The mismatch is that you need stable props from the bottom up, and you enforce stable props from the top down. Any oversight in between (even indirectly, like in a hook or external module) creates a bug that appears silently and regresses performance.