Fork me on GitHub

Ahad Bokhari

Hooks - Classes Confuse Both People & Machines, says React. I Say, Classes Confuse JavaScript

Edit   ·   258 words

Is it that hard to remember to bind event listeners or create a class level component? The engineers at Facebook seem to think so! How about classes are a plague to the prototypal nature of JavaScript? Something that most developers don’t understand is that
the best way to optimize and work with JavaScript within it’s own paradigm is to use object composition and composition inheritance as opposed mimicking class inheritance using prototypes.

That’s just talking about Vanilla JavaScript of course, but it’s cool to see Facebook make such bold claims and continue to take the side of JavaScript’s real nature.

I like what I hear from Facebook, and this is one of the reasons that the JavaScript community (…and of course myself included) loves React - because it tries to remain as close to JavaScript as possible. With the new hooks proposal we are going for a more functional approach omitting class components and some of the complexities therein, ‘this’ and that sort of stuff.

Ahhh, function composition - hooks embrace functions in a traditional way and try to keep things simple for newer developers immigrating to the environment. I’ve only been reading about them lately, but haven’t changed a spot of any of my code to incorporate them. Mind you, class level components aren’t going anywhere for the foreseeable future and hooks will be used side-by-side along with classes.

This looks promising, but I wouldn’t rush into refactoring my whole code base just yet. Keep an eye on this and perhaps even learn hooks, that’s for sure.