React uses JSX instead of regular JavaScript.
JSX is a JavaScript syntax extension that looks a lot like XML.
React JSX syntax
We don't necessarily need to use JSX, but it has the following advantages:
JSX executes faster because it is optimized after being compiled into JavaScript code.
It is type-safe and errors can be found during the compilation process.
Writing templates using JSX is simpler and faster.
React JSX example
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>php.cn React 实例</title>
<script src="https://cdn.bootcss.com/react/15.4.2/react.min.js"></script>
<script src="https://cdn.bootcss.com/react/15.4.2/react-dom.min.js"></script>
<script src="https://cdn.bootcss.com/babel-standalone/6.22.1/babel.min.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/babel">
ReactDOM.render(
<div>
<h1>php中文网</h1>
<h2>欢迎学习 React</h2>
<p data-myattribute = "somevalue">这是一个很不错的 JavaScript 库!</p>
</div>
,
document.getElementById('example')
);
</script>
</body>
</html>Run instance »
Click the "Run instance" button to view the online instance

