DEV Community

React is finally JavaScript

Steve Brownlee on September 29, 2019

"Classes are the future of JavaScript because of React." I heard this many times over the last few years, and I remained highly dubious because, I...
Collapse
 
mindplay profile image
Rasmus Schultz

I disagree that hooks are "functional composition well executed".

The engine internally counts calls to establish the identity of individual states and effects - it requires a custom linter to validate that valid JavaScript is also valid React.

To me, this goes against the idioms of the language - it's an attempt to make something that evokes feelings of pure functional composition, when in fact it's largely a language "hack".

I find it by all means far more unnatural and further from the language than classes.

Not saying that classes are or were a great way solve these problems, but at least it was leveraging the language rather than trying to subvert it.

I hope we'll see more UI frameworks in the future that really compose functions - without the hacks - the way React hooks appear to do until you understand what's really going on beneath the hood. 😐

Collapse
 
dorshinar profile image
Dor Shinar • Edited

I disagree. I think over the years many JavaScript developers found clunky ways to mimic the behavior of classes while refusing to name them which, for the sake of being functional (looking at you module pattern). Classes absolutely have a role, especially in such a poorly designed language, with such a huge ecosystem.

Hooks in react are a great edition, but I don't think they make classes obsolete.

Collapse
 
_ezell_ profile image
Ezell Frazier

Heard of Web Components?

The class syntax is there.

But if you don't like syntactical sugar, we could always make it "JavaScript".

Bottom line, do what works best for you.

Collapse
 
webdevinci profile image
webdevinci

Right? Lets move away from react and all frameworks/libs and the dependencies and patterns they force on us.... Same as jQuery, these will also become obsolete and we'll be back to vanilla. Start the movement to liberal JS and web components today!

Collapse
 
arizonatribe profile image
David Nunez • Edited

Well said. I would even recommend doing a js-benchmark comparison of invoking multiple methods on a class instance vs the same methods composed into an object directly (individual functions as fields in an object directly). The syntactic sugar of post-ES2015 classes can't make up for such a drastic performance drop. But this is one big reason (in JavaScript) to favor composition over inheritance.

Languages like Java are built on top of a JVM highly optimized for object oriented programming (C# too, although it isn't as bare metal fast these days as Java). JavaScript meanwhile is a LISP/Scheme/SmallTalk clone with some "C"-like syntax.

Lots of people spend their week tinkering with the many compile-to-JS solutions and I wish them great enjoyment in their efforts. I just hope they don't spend their entire careers coding JavaScript from their favorite abstraction layer and never get the opportunity to see all the low-level tricks and simplicity of vanilla js.

Collapse
 
jascomp profile image
Jason Holden

Question: How are folks debugging React in the browser when most code is transpiled (God I hate that word).

Collapse
 
couch3ater profile image
Connor Tangney
Collapse
 
jascomp profile image
Jason Holden

But how are you debugging the raw JS?

Thread Thread
 
sonicoder profile image
Gábor Soós

Source Maps?

Thread Thread
 
couch3ater profile image
Connor Tangney

👆

Collapse
 
drewstaylor profile image
Drew Taylor

Imho any discussion of JavaScript classes without a mention of Typescript is a bit hasty.

Collapse
 
codelitically_incorrect profile image
codelitically_incorrect

You have a lot to learn

Collapse
 
marcus-sa profile image
Marcus S. Abildskov • Edited

Yes.
This post is so opinionated and poorly written.
The quote "Classes are the future of JavaScript because of React." is completely nonsense.
React was never the reason why people began to use classes, nor why they were even put in the ES spec.
Classes are "natively" supported, so how can they not be intended usage?
There's literally no context in this absurd post at all, as everything gets switched around.
Are we talking about React only, Node.js, ES3, ES6 or transpilers?
I mean what's the point?

Collapse
 
yawaramin profile image
Yawar Amin

Out of curiosity ... do you use vanilla JavaScript? Or some typed flavour?

Collapse
 
xeroneon profile image
Andrew Vasquez

So many people in the comments disagreeing but I definitely agree with you

Collapse
 
stevebrownlee profile image
Steve Brownlee • Edited

I do not mind at all when people disagree with me. They are allowed to be wrong.