4 ms·
lol pre hooks world was fine. Hooks are great but react took over the world because of the clarity of class component lifecycles. If hooks were there from the s
by yawnr 3y ago
lol pre hooks world was fine. Hooks are great but react took over the world because of the clarity of class component lifecycles. If hooks were there from the start it wouldn’t have been as popular.
Also Vercel/NextJS is like if DHH was charging people to use Rails. We are in the “enshittification” part of react development.
- whoknowsidont 3y ago>because of the clarity of class component lifecycles. is this satire?
- throwaway290 3y agoAh, the clarity of useEffect(() => { return () => { handleUnmount() } }, [])! How did they manage to live with the ugly componentWillUnmount() { handleUnmount() } for all those years? (By the way, don't forget that [] or it does a completely different thing that you never want.)
- yawnr 3y agouseEffect is the biggest source of bugs in any react codebase bar none
- shmde 3y agoI started off with hooks and started learning about class components just to clear interviews and damn it provides clarity of when, how components are gonna re-render. If you can get past the HOC hell hole and the "this.add = this.add.bind(this)". I felt it made it very clear how and in what order things run. Its definitely true when OP said if things did not get so clear with class components we would never have gotten hooks.
- whoknowsidont 3y ago> I felt it made it very clear how and in what order things run. I'm sorry, the entire community rallied around hooks PRECISELY because the life cycle methods were not clear and were very problematic. It seems extremely strange to see such opinions. When you see a hook you know exactly when it's going to execute and why and because of what. You don't have to layer the methods with tons of checks making sure the life cycle method has been run in the right context, it literally just works.
- yawnr 3y agoHooks gained momentum because of advantages in composability and removing a lot of pain with HOCs. Brevity also helped. The obfuscation about re-renders and memoization of variables is absolutely a downside that I see junior devs really struggle with all the time — something that “just works” with class components. Anyway, both are fine and usable haha. Just think there are arguments to be made on both sides.
- yawnr 3y agoFor what it’s worth there is a babel plugin to auto bind arrow functions as methods so you never have to do this.
- bornfreddy 3y agoNo. Hooks have their advantages over classes, but readability is not one of them, by far.