3 ms·
I wouldnt call it a "gotcha". Using vanilla javascript you'd be using className as well: document.body.className = 'class1 class2' JSX chose to align name
by orangepanda 3y ago
I wouldnt call it a "gotcha". Using vanilla javascript you'd be using className as well:
document.body.className = 'class1 class2'
JSX chose to align names to the DOM spec [0]. Same for htmlFor and friends.
[0] https://dom.spec.whatwg.org/#ref-for-dom-element-classname%E2%91%A0 https://dom.spec.whatwg.org/#ref-for-dom-element-classname%E...
- regularfry 3y agoIt's a gotcha because it looks wrong. The surface syntax looks like a tag, which prompts the thought "class". You've got to have additional information to know that's not what's needed.
- cesarb 3y ago> JSX chose to align names to the DOM spec [0]. Same for htmlFor and friends. And the DOM spec changed these names because "class" and "for" are reserved words in Java (and if you look closely, you'll notice that the main target language for the DOM spec was Java). If you're writing a template language, you don't need to be bound by reserved words in another language, and matching the original attribute name is more intuitive than matching the underlying DOM implementation. (But I can understand why JSX did that: since it maps directly to DOM calls, using the same name as DOM avoids the need for a table mapping from the attribute name to the DOM name. That is, implementation convenience was more important than usability.)