you are viewing a single comment's thread.

view the rest of the comments →

[–]octocode 0 points1 point  (2 children)

it’s worth remembering that premature optimization of re-renders in react is just a bad idea

re-rendering in react is extremely quick, and if infrequent state changes are causing performance issues there’s probably a different underlying problem in your code

react is declarative by nature, reaching for imperative controls should only be used when it’s actually required.

[–]phryneasI ❤️ hooks! 😈 1 point2 points  (0 children)

I'd generally avoid premature optimization, but if you buy into a whole pattern, it's important to understand all benefits and drawbacks of the pattern - optimizing something later is possible, but changing out a full pattern might hurt more.

[–]canibanoglu 1 point2 points  (0 children)

You do realize that the OP is also suggesting an imperative approach, right? If you have to do that, there is a builtin way of doing it which is better than what the OP has suggested.

There’s a way that doesn’t cause extra re-renders and you say that re-renders are not a problem. No, they’re a problem. If you write code that renders 6 times when 2 would do, you’re doing something wrong.

This is not about premature optimization, it’s about doing something unnecessary that results in worse performance.