Hacker News new | ask | show | jobs
by _uhtu 2855 days ago
I love the react team for what they're doing here, but I have a feeling that the className -> class change would be a huge mistake. It makes it so that the ({ class }) => ... syntax would no longer work since it's a reserved keyword. A simple find and replace is not going to work and a pretty sophisticated code mod would be required, and even then it still means convenient practical uses like the syntax mentioned above would never be possible.

It also brings up significant package compatibility issues, if even a single package I use uses className I can't upgrade React, if a single one uses class I can't upgrade it. I'd rather not deal with a Python 2 -> 3 situation in React.

4 comments

Yes, I’m disappointed by this too. It seems to be motivated by thinking about HTML/JSX, rather than the DOM where that attribute really is called className. To me, one of the appealing things about the React model is that the core is a relatively lightweight abstraction on top of the DOM, and other parts of the ecosystem (including JSX templating) are optional. This ends up being one more special case in the React core.

Edit: babel-plugin-react-html-attrs seems like the right solution to people who want to use “class” in their templates.

The increased simplicity and straightforward API seems to outweigh the edge cases though. React has always been very good at backwards compatibility and slowly migrating though, and it'll likely be the case here. The recent lifecycle methods change is a good example.
No reason this couldn't be backwards compatible...
> Note we can’t just allow both without warnings because this makes it very difficult for a component ecosystem to handle. Each component would need to learn to handle both correctly, and there is a risk of them conflicting. Since many components process className (for example by appending to it), it’s too error-prone.

Unless you meant that there's no reason the code mod they release won't work - I agree with that.

Yeah, that's the only change I'm not thrilled with.