▲ | Etheryte 6 hours ago | |
I'd say that most of the time, that's the wrong thing to do. For the vast majority of effects, you don't actually want to call it for every variable that's referenced in it. A good example is literal arrays, functions, and so on, if you have a prop that's an inline function definition, you'll be calling the effect on every render because the reference is new. You could work around this by memoing every inline function definition, but at that point, what are we even talking about. Hooks are a leaky abstraction, and while they do solve many real problems, they come with a lot of heavy baggage once you get into the thick of it. | ||
▲ | rimunroe 5 hours ago | parent [-] | |
> You could work around this by memoing every inline function definition, but at that point, what are we even talking about. This is a normal part of optimizing React components and the exact reason for the React compiler’s existence. |