2 ms·
Exactly! I could not put it better. All the talk about side-effects. Hooks make side effects more confusing, not less, for the reasons you perfectly explained.
by mejutoco 4y ago
Exactly! I could not put it better. All the talk about side-effects. Hooks make side effects more confusing, not less, for the reasons you perfectly explained.
Small rant ahead. Disclaimer: I find React very useful, just not this constant churn of approaches.
One solution would be to make all state pass through a single point (like Elm or Redux) but some people do not like this because it "limits" them. Limiting side-effects lowers cognitive load, same as Type systems are usually not Turing-complete. Limits can be good.
Same with Context, which is practical because you can write things from anywhere. Congratulations, we were concerned about side-effects and now we are basically using a global variable.
It is like some people talk about side-effects and functional programming and they think it involves using map and filter and done and they don't think deeper about what it means, and see no contradiction in it where it contradicts the principles they are promoting.
- wildrhythms 4y agoAll true. I work on a massive React codebase and it is a challenge to follow the logic because at any given time there could be a dozen effects firing off from a single state change. Granted, having the dependency array helps follow what's firing off, but when effects kick off other effects it gets into a mess. (Probably a sign that we should refactor some things) This problem isn't solved by class-based components either; years ago when I first started working on the codebase I found class-based components with gigantic componentDidUpdate() full of hard to follow conditionals and setting state. That said, hooks makes it easier to refactor problems like this in my experience.