学习笔记《JSX》

JSX 可以被视为一种 JS 的模板语言,形如:

const element = 

Hello, world!

;

使用引号来表示 JS 代码:

const element = (
  

Hello, {formatName(user)}!

);

如果是多行的话,可以加一个括号:

const element = (
  

Hello!

Good to see you here.

);

在 React 中三种等价的创建形式:

const element = (
  

Hello, world!

); const element = React.createElement( 'h1', {className: 'greeting'}, 'Hello, world!' ); // Note: this structure is simplified const element = { type: 'h1', props: { className: 'greeting', children: 'Hello, world' } };

就是这些,是不是非常简单:)

你可能感兴趣的:(学习笔记《JSX》)