class vs className in React 16

后端 未结 8 2401
感动是毒
感动是毒 2020-11-29 02:56

I saw that React 16 allows for attributes to be passed through to the DOM. So, that means \'class\' can be used instead of className, right?

I\'m just wondering if

8条回答
  •  迷失自我
    2020-11-29 03:46

    Just to shed a little more light, on top of the other good answers already given:

    You'll notice that React uses className instead of the traditional DOM class. From the docs, "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."

    http://buildwithreact.com/tutorial/jsx

    Also, to quote zpao (a React contributor / facebook employee)

    Our DOM components use (mostly) the JS API so we opted to use the JS properties (node.className, not node.class).

提交回复
热议问题