Introducing JSX
-
JSX
語法實際上是在創建對象,產生的對象稱爲React elements
; -
對這些
React elements
進行渲染,構建出DOM
const element = (
<h1 className="greeting">
Hello, world!
</h1>
);
// => 等於如下寫法:
const element = React.createElement(
'h1',
{className: 'greeting'},
'Hello, world!'
);
// => 創建出的對象(React elements)如下形式:
// Note: this structure is simplified
const element = {
type: 'h1',
props: {
className: 'greeting',
children: 'Hello, world!'
}
};
更多討論:issue