3 ms·
I was relatively happy with the React class model, for me it was very clear just to override any required methods in a class. To this day if I need to do somet
by liendolucas 4y ago
I was relatively happy with the React class model, for me it was very clear just to override any required methods in a class.
To this day if I need to do something in React I can pick it up quickly because is a very simple model: it follows the template design pattern, which is one of the most powerful and dumb design patterns (I'm talking obviously about the class model).
What's my current issue with React? Well in the same way that they have decided to go with hooks and all that, nothing is preventing those folks tomorrow to wake up to say: "You know what? What we really really need is not functional components but a hybrid approach, not fully functional not fully object oriented" and then the game starts again.
I worked for a very limited time in one company not long ago, and a guy there came and said something like: "We really should start using hooks" and I replied: "Really? Why? Can you show me a true or concrete advantage using the functional style over the OO approach?" then he said: "Well, I don't really need to do that just watch this video" and sent me a link of a video (if I recall correctly) of the creators explaining all the hooks stuff. I didn't even bothered to continue discussing (how can you discuss when someone is 100% biased?).
My point is that many people out there just take for granted whatever ideas these people are pushing out and not questioning things anymore. I'm not saying that hooks are good or bad a thing (I really don't know and if I need to learn hooks because that's the style used in a codebase, sure I'll do it and probably learn something), but blindly embracing things just for nothing is harmful.
- ruicaridade 4y agoTo me, the main benefit of react hooks is it eliminates higher-order component hell. It's so much easier to extract common behaviour from different components to a re-useable hook, rather than wrapping a class with a million different higher-order components: `withRouter(withFoo(withBar(MyComponent)))`.
- codingdave 4y agoWhen hooks came out, myself and the other senior devs on our team had that same inertia-driven reaction. We knew classes, we were comfortable with classes, and they worked. So we asked the same question - "Why hooks?" So we sat down and actually used hooks for a few days - refactored small and large components to be sure we understood them and saw the difference in the code. We found it to be a perspective change -- once we made that change and got used to the new syntax, we loved it. Our code was simpler and easier to maintain. Once we really learned when to use useEffect so as to not abuse it for everything under the sun... the code got better still. So while you are correct that blindly embracing hooks would be harmful... Blindly rejecting them is equally harmful.
- willio58 4y agoSame experience for my team a couple years back. We hated the idea of changing everything to hooks, then we actually started using them and fell in love. So much complexity fell out of our code we couldn't justify sticking with class components. Having said that, there are some gotchas with hooks that aren't trivial and can make them difficult to use/understand without significant comments. But hey, what code doesn't fit that description?