JSX tag with className attribute render a dom node with both class and className attribute
See original GitHub issueThe following example illustrates the issue:
const Button = ({label}) =>
<button className="my-button">{label}</button>
;
const view = () =>
<div>
<Button label="Click me" />
</div>
;
The rendered output (in Chrome, macOS High Sierra)
<button class="my-button" classname="my-button">Click me</button>
If I use class
instead of className
it renders correctly.
const Button = ({label}) =>
<button class="my-button">{label}</button>
;
Issue Analytics
- State:
- Created 6 years ago
- Comments:20 (11 by maintainers)
Top Results From Across the Web
Why React uses className over class attribute
Explanation: The only reason behind the fact that it uses className over class is that the class is a reserved keyword in JavaScript...
Read more >DOM Elements - React
In React, all DOM properties and attributes (including event handlers) should be camelCased. ... To specify a CSS class, use the className attribute....
Read more >class vs className in React 16 - Stack Overflow
HTML elements have attributes like class , and then once parsed a DOM node is created with properties like className .
Read more >Why does React use className instead of a class attribute?
When applying CSS classes to all common DOM and SVG elements like buttons, li, a, and div in React, we use the className...
Read more >Why you have to use className in React, but not in Preact?
The only reason behind the fact that it uses className over class is that the class is a reserved keyword in JavaScript and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well, I’ve decided I can live with this for now - if this thing really catches on and the SAM pattern works out the way I’m hoping for, I might take another stab at this, but for now, it’s functional.
Good enough for government work 😂
@mindplay-dk Okay, I fixed this.
I found at least another property that was problematic, innerHTML. I don’t know if this was pointed out to me before, but it came up in a discussion with @frenzzy. 🎉