Warning: Unknown DOM property class. Did you mean className?

jsalonen picture jsalonen · Jun 21, 2015 · Viewed 65.9k times · Source

I've just started exploring React, by adding a component with a simple render function:

render() {
  return <div class="myApp"></div>
}

When I run the app, I get the following error:

Warning: Unknown DOM property class. Did you mean className?

I can solve this by changing class to className.

The question is; does React enforce this convention? Also why do I need to use className instead of the conventional class? If this is a restriction then is it due to JSX syntax or somewhere else?

Answer

Viacheslav picture Viacheslav · Jun 21, 2015

Yes, its a React convention:

Since JSX is JavaScript, identifiers such as class and for are discouraged as XML attribute names. Instead, React DOM components expect DOM property names like className and htmlFor, respectively.

JSX In Depth.