React

React(createElement())

2017-10-22  本文已影响15人  余生筑

createElement

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.

上一篇下一篇

猜你喜欢

热点阅读