Reputation: 778
I've been trying out React on a project for weeks now. And I just remembered that I should use className
instead of class
in regular DOM and SVG, because class
is a reserved keyword in JS.
However, all my components are using class
so far. For example:
export default class Header extends React.Component {
render() {
return (
<div class="Header">
<img class="Logo" src="./interface/images/ea-white.png"/>
<h1 class="Title">{this.props.title}</h1>
</div>
);
}
}
Why haven't I got any syntax error? Does React DOM have to use className
? What could happen if I keep it this way?
Edit: Yes, the CSS files worked normally all this time. There's no warning in my console (which is weird).
Upvotes: 2
Views: 1925
Reputation: 5645
It currently works, but React will throw a warning in your console. I would recommend using className
considering this is what React wants you to do. If you continue to use class, there may be a time when React stops supporting this.
Upvotes: 3
Reputation: 860
React throws a warning when you use an unknown property such as class
on an element.
It also points to the source line number, thanks to this pr https://github.com/facebook/react/pull/6398
Upvotes: 2