|
|
|
|
|
by bastawhiz
321 days ago
|
|
You're making the same argument as the author. As they said, the only two solutions are: 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. |
|
> you need stable props from the bottom up, and you enforce stable props from the top down.
You don't need stable props from the bottom up. Component will always react to props change and will returns a new Tree. The function for that are going to be run multiple times and you're not supposed to control when it does. So the answer is to treat everything that comes from the parent as the gospel truth. And any local transformations should be done outside of function calls.
#1 is not needed. Memoization concerns is always local to the component, as long as you ensure that the props you're sending down is referentially stable, you're golden.
#2 is not needed. Again your only concern is the current component. Whatever everyone does elsewhere is their bad practices. Maybe they will cast your carefully constructed type into any or try/catch your thougthful designed errors into oblivion along the way too. The only thing you can do is correct them in PR reviews or fix the code when you happen upon it.