React中的JSX和React elements的概念
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!' } };