4 ms·
> I don't think the `className` argument sticks. `class` is reserved so you can't use it. But you can use it. JSX nodes get compiled into React.createElement c
by epidemian 9y ago
> I don't think the `className` argument sticks. `class` is reserved so you can't use it.
But you can use it. JSX nodes get compiled into React.createElement calls with object literals[1], and {class: "foo"} is a perfectly valid object literal in JS, s there's nothing stopping `<div class="foo" />` to get compiled into `React.createElement("div", {class: "foo"})`
In fact, other frameworks that support JSX syntax allow the use of `class` instead of `className`[2], so it's not a limitation of JSX per-se, it's just a design decision on part of React (and an annoying one at that).
[1]: As noted in the first code snippet on the React homepage https://facebook.github.io/react/ https://facebook.github.io/react/
[2]: E.g., Mithril https://mithril.js.org/jsx.html#jsx-vs-hyperscript https://mithril.js.org/jsx.html#jsx-vs-hyperscript