4 ms·
Having used React hooks for the past couple of months, I think I've come to the conclusion that I'm not going to recommend any body to switch away from class co
by bgdam 8y ago
Having used React hooks for the past couple of months, I think I've come to the conclusion that I'm not going to recommend any body to switch away from class components.
I understand that hooks solve the problem of being able to compose side-effects and lifecycle in your components, but honestly, in the last three years of using React, I don't think I've ever actually had a scenario where hooks would have been a great solution for me. I'm not sure if this means I've been designing my React components very well, or very badly or what.
While hooks look like they might be good at some things (ex: useState is awesome), I think they come with too many subtle gotchas (the amount of literature on handling these gotchas, that's been written in the few months of hooks being in beta is mind-blowing) that I'd much rather just use class components.
- thatswrong0 8y agoWhat gotchas are you referring to besides exhaustively listing dependencies and implementing something like `setInterval` via hooks?
- ryansolid 8y agoThat's ultimately it isn't it. I think Hooks are great and I've been using them and would use them for everything. I'm also a Dev manager, and understanding those gotcha's it isn't even about not knowing which would be an obstacle for less experienced developers, but how easily you repeatedly accidentally fall into them. It's hard. I feel like they are 90% right, but unless you are not only a very competent developer but also insanely careful you will make many mistakes. I perhaps am a bit more torn as I have experience with fine grained libraries like Knockout and MobX and I even more so see the benefit of the potential here. I think the idea of it is a better, more clear way to solve problems (from previous experience). But the number of times I've missed [], or forgot to close over state properly even knowing. I usually catch myself but I can only picture the team biting into this.