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