JSX------HTML tags vs React Components:

  1.To render a html tag,just use lower-case tag names in JSX; 

var myDivElement = <div className="foo" />;
React.render(myDivElement, document.body);

  2.To render a React Component,just create a local variable that starts with an upper-case latter;

var MyComponent = React.createClass({/*...*/});
var myElement = <MyComponent someProperty={true} />;
React.render(myElement, document.body);

  

JSX-------The Transform

  React JSX transforms from an XML-like syntax into native JS xml elements,attributes and children are transformed into arguments to React.createElement

var Nav;
// Input (JSX):
var app = <Nav color="blue" />;
// Output (JS):
var app = React.createElement(Nav, {color:"blue"});

  

var Nav, Profile;
// Input (JSX):
var app = <Nav color="blue"><Profile>click</Profile></Nav>;
// Output (JS):
var app = React.createElement(
Nav,
{color:"blue"},
React.createElement(Profile, null, "click")
);

  

Javascript Expressions

  1.Attribute Expressions:To use a JS expression as an attribute value,wrap the expression in a pair of curly braces({})instead of quotes("").

// Input (JSX):
var person = <Person name={window.isLoggedIn ? window.name : ''} />;
// Output (JS):
var person = React.createElement(
Person,
{name: window.isLoggedIn ? window.name : ''}
);

  2.Child Expressions:Likewise,JS expressions may be used to express children:

/ Input (JSX):
var content = <Container>{window.isLoggedIn ? <Nav /> : <Login />}</Container>;
// Output (JS):
var content = React.createElement(
Container,
null,
window.isLoggedIn ? React.createElement(Nav) : React.createElement(Login)
);

  3.Comments:it's easy to add comments within youe JSX,they are just JS expressions. you just need to bo careful to put {} around the comments when you are within the children sction of a tag.

var content = (
<Nav>
{/* child comment, put {} around */}
<Person
/* multi
line
comment */
name={window.isLoggedIn ? window.name : ''} // end of line comment
/>
</Nav>
);

  

最新文章

  1. from表单如果未指定action,submit提交时候会执行当前url
  2. [转]CIDR简介
  3. objective-c系列-NSMutableArray
  4. java判断request请求是手机还是pc终端
  5. HTML5基础
  6. MFC ADO连接Oracle12c数据库 客户端环境搭建
  7. graph | Max flow
  8. 常见设计模式解析和实现(C++)Adapt模式
  9. ssh连接超时问题解决方案
  10. java多线程安全问题-同步修饰符于函数
  11. Thinkphp 3.0-3.1版代码执行漏洞
  12. System.ComponentModel.DataAnnotations 冲突
  13. shell高级特性-4
  14. Ambari集成Kerberos报错汇总
  15. 服务器安装ubuntu 14.04 server,开机启动屏幕不停滚动错误WRITE SAME failed. Manually zeroing
  16. 量化交易-外汇交易-MetaTrader5
  17. SuperMap 二维地图和三维场景弹窗窗口大小控制
  18. 用actor model实现intel tbb这样的用法
  19. java代码------------条件运算符 ?:
  20. hdu 1130,hdu 1131(卡特兰数,大数)

热门文章

  1. SpringMVC-DispatcheServlet
  2. hibernate的1+n
  3. 扩展django的User的部分方法
  4. VS2010默认属性文件配置
  5. 学习Find函数和select
  6. 探索javascript----拖拽
  7. 遗传算法的C语言实现(一):以非线性函数求极值为例
  8. [Python Fabric] [SSH] Mac OS X 10.9 + Vagrant虚拟环境使用Python Fabric进行SSH远程登录的简单实验
  9. java 调用 sql server存储过程
  10. repo upload上传提交时发生remote rejected异常