2.4 Specifying Children with JSX

2017-03-21  本文已影响0人  人头原子弹
If a tag is empty, you may close it immediately with />, like XML:

如果是一个空标签,你可以像XML那样通过 />快速改变它。

const element = <img src={user.avatarUrl} />;

JSX tags may contain children:

JSX标签也许包含子标签:

const element = (
   <div>
      <h1>Hello</h1>
      <h2>Good too see you here!</h2>
   </div>);

Caveat:

Since JSX is closer to JavaScript than HTML, React DOM uses camelCase property naming convention instead of HTML attribute names.

JSX比HTML更接近JavaScript,React Dom 使用驼峰属性命名规则替换HTML的属性名称。

For example, class becomes className in JSX, and tabindex becomes tabIndex.

例如在JSX里面class变成了className,而tabindex变成了tabIndex。

上一篇下一篇

猜你喜欢

热点阅读