Settings

Theme

Ask HN: Why Did React Switch to ES6 Classes?

1 points by jan-jakub 9 years ago · 1 comment · 1 min read


I tried to find a justification for that change in the API, but couldn't find any. Using ES6 Classes in React seems more tedious to me, as I have to bind methods manually, so I see one downside and no upsides. Is it known what was the React guys' reasoning behind that switch?

acemarke 9 years ago

The React team has discussed this many times.

`React.createClass` was created at a time when there were no classes as part of the JS language itself, and every library was busy inventing its own class-like inheritance implementation. Now that that classes are an actual part of the language, they're a common standard of syntax and behavior that tools can understand, so there's no reason to keep using a homegrown implementation. In addition, in React 16 the React team will remove `createClass` from the main React package and move it into a separate package, thus shrinking package size.

There's a variety of approaches to manage method binding. See the "Using React with ES6" section of my links list for discussion and information: https://github.com/markerikson/react-redux-links/blob/master...

(I'd normally go dig up some links to comments from the React team, but I'll leave that as an exercise for the asker this time - trust me, you shouldn't have to look too hard.)

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection