Hacker News new | ask | show | jobs
by zeven7 3420 days ago

    > Regarding class vs. className: class is a reserved word
    > in JS. It's not really a perf thing, it's the fact that
    > JSX was intended as a very simple transform. If JSX used
    > class instead of className, the transpiler would need to
    > be contextual since "class" would sometimes mean "css
    > class" and sometimes "JavaScript class".
I don't think React should have used `class` instead of `className`, but this isn't the reason.

    <foo className="bar" />
compiles to

    React.createElement("foo", { className: "bar" });
It could have just as easily have been that

    <foo class="bar" />
compiles to

    React.createElement("foo", { 'class': "bar" });
as far as JSX is concerned (or even without the quotes in an ES5 world).
1 comments

The output isn't the problem; it's that "class" is also a keyword in the JSX input. I admit, though, I'm not intimately familiar with the JSX transpiler and am just guessing as to their motives.