2 ms·
> Hooks are something I didn’t ask for. I did. Reusable components with lifecycle events were a pain. Now if I want to add some complex lifecycle logic, I can
by satvikpendem 4y ago
> Hooks are something I didn’t ask for.
I did. Reusable components with lifecycle events were a pain. Now if I want to add some complex lifecycle logic, I can package that up into a neat, tidy function (which is all hooks are, stateful functions) and call it.
In my experience, many people who don't see the value of hooks have never experienced the pain points that they solve, or they're just newer to React and have never dealt (extensively) with class components.
- PaulHoule 4y agoPersonally I know how to do very complex things with class components and make them reusable but that's because I have been doing object oriented programming intensively since 1994. (Kinda tried writing serial communication code in C++ in 1989 but I never really got OO until I got into Java.) My perception of hooks is that nobody really understands them or what the real rules for using them are, but it usually works when people copy stuff out of stackoverflow until it doesn't. The fact that it is functions and not methods seems to make some people squee ("It's functional!") but it is pure insanity and not functional at all because the order that hooks get called matter.