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 實(shí)例</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中文網(wǎng)</h1> <h2>歡迎學(xué)習(xí) React</h2> <p data-myattribute = "somevalue">這是一個(gè)很不錯(cuò)的 JavaScript 庫!</p> </div> , document.getElementById('example') ); </script> </body> </html>
Run instance ?
Click the "Run instance" button to view the online instance