React(createElement())
2017-10-22 本文已影响15人
余生筑
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.