• Grammer


    Now let's study the grammer for react.

    Usually, we write the js code and html code in a separate way. Just as below:

    But react changed the way. It makes easier to write js & html tags and you can mix them together without caring about anything unless you obey the rule below:

    Each time when react met <,it will compile with html tags ; If react met { ,it will compile with js.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="../js/bootstrap.css">
        <script src="../js/react.js"></script>
        <script src="../js/react-dom.js"></script>
        <script src="../js/browser.js"></script>
        <title>React02</title>
    </head>
    <body>
    <div id="example"></div>
    <script type="text/babel">
        var names = ['Alice', 'Emily', 'Kate'];
    
        ReactDOM.render(
                <div>
                    {
                        names.map(function (name) {
                            return <div>Hello, {name}!</div>
                        })
                    }
                </div>,
            document.getElementById('example')
        );
    </script>
    </body>
    </html>
    

    Open the browser, you will see:

    Another example

    
    var arr = [
      <h1>Hello world!</h1>,
      <h2>React is awesome</h2>,
    ];
    ReactDOM.render(
      <div>{arr}</div>,
      document.getElementById('example')
    );
    

    You can change the world with your heart,even a lot of changes sometimes unless you won't geiv up....
  • 相关阅读:
    2017.5.5上午学习内容
    2017.5.4下午学习内容
    2017.5.4上午学习内容
    2017.5.3上午学习内容
    2017.4.28下午学习内容
    2017.4.28上午学习内容
    scrapy项目的代码书写流程
    pycharm的远程连接
    mongodb的安装---linux篇
    mongo的安装和使用---windows篇
  • 原文地址:https://www.cnblogs.com/xiongwei2017/p/7350659.html
Copyright © 2020-2023  润新知