React(createElement())

createElement

  • createElement()是Babel编译jsx以获取virtual DOM的工具
const element = (
  <h1 className="greeting">
    Hello, world!
  </h1>
);

Babel利用createElement()会将其编译为

const element = React.createElement(
  'h1',  //
  {className: 'greeting'},
  'Hello, world!'
);

显然这种编译方法是构造了一个含各项属性的object

tagname:'h1'
attribute: {className: 'greeting'},
children:"Hello World"

React reads the objects and uses them to construct the DOM and keep it up to date.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 比特币的功能相对于姨太,瑞波,比特股,比特币的功能最少,但是比特币也有一个功能,就是姨太,瑞波,比特股,各种ico...
    比特观点阅读 192评论 0 0
  • 作者:明道创始人任向晖 这篇文章能够帮助你分步骤,组织全员将明道用到极致。这无关你为明道支付的微乎其微的成本,而是...
    philren阅读 953评论 1 4