question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSX tag with className attribute render a dom node with both class and className attribute

See original GitHub issue

The 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:closed
  • Created 6 years ago
  • Comments:20 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
mindplay-dkcommented, Jan 2, 2018

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 😂

2reactions
jorgebucarancommented, Jan 3, 2018

@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. 🎉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found