React Learn A

Source: Internet
Author: User
Tags cloudflare



Recent project preparation using react as the front end, the main first comparison of fire, the second relatively small. Take the time to study first.



First download the resource file: less than 50KB after compression, is quite small oh.






Where:react.jsis the core library of React,react-dom.jsis to provide DOM-related features, react-dom-server.js is the server-side rendering of the DOM function, React-with-addons is some plug-in features.



OK, let's leave it to the server and addons, start with react and react-dom a try and use the official example:


 
 
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Hello React!</title>
    <script src="build/react.js"></script>
    <script src="build/react-dom.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
  </head>
  <body>
    <div id="example"></div>
    <script type="text/babel">
      ReactDOM.render(
        <h1>Hello, world!</h1>,
        document.getElementById(‘example‘)
      );
    </script>
  </body>
</html>


Good running success:






And look at the source code: <script src= "Https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js" ></script >,react The download package does not have it, what is this?



Browser.js is the browser version of Babel, What is Babel?



Babel is a JavaScript compilation tool, what do you want to compile the tool for?



Look at the source code


In See <script type= "Text/babel" > here named Use Babel, so to reference browser.js, otherwise the program cannot execute.



Okay, what if you don't want to use it?



Then use the native JS or compiled JS:


 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>react demo</title>
    <script src="../src/react-0.14.3/build/react.js"></script>
    <script src="../src/react-0.14.3/build/react-dom.js"></script>
</head>
<body>
    <div id="example"></div>
    <script type="text/javascript">
      ReactDOM.render(
        React.createElement(‘h1‘, null, ‘Hello, world!‘),
        document.getElementById(‘example‘)
      );
    </script>
</body>
</html>


Remove Browser.js, modify <script type= "Text/javascript" >.



One thing to add: Before react use jsxtransformer to translate JSX, which type is <script type= "Text/jsx", and v0.14 is used from Babel. Babel can not only translate jsx, can also compile ES, may Babel use will bring better development to react, let us wait and see.



React Learn A


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.