MOCKSTACKS
EN
Questions And Answers

More Tutorials









React Installation or Setup


ReactJS is a JavaScript library contained in a single file react-.js that can be included in any HTML page. People also commonly install the React DOM library react-dom-.js along with the main React file:

Basic Inclusion


<!DOCTYPE html>
<html>
 <head></head>
 <body>
 <script type="text/javascript" src="/path/to/react.js"></script>
 <script type="text/javascript" src="/path/to/react-dom.js"></script>
 <script type="text/javascript">
 // Use react JavaScript code here or in a separate file
 </script>
 </body>
</html>

To get the JavaScript files, go to the installation page of the official React documentation.

React also supports JSX syntax. JSX is an extension created by Facebook that adds XML syntax to JavaScript. In order to use JSX you need to include the Babel library and change
 <script type="text/javascript"> to <script type="text/babel">
in order to translate JSX to Javascript code.

<!DOCTYPE html>
<html>
 <head></head>
 <body>
 <script type="text/javascript" src="/path/to/react.js"></script>
 <script type="text/javascript" src="/path/to/react-dom.js"></script>
 <script src="https://npmcdn.com/babel-core@5.8.38/browser.min.js"></script>
 <script type="text/babel">
 // Use react JSX code here or in a separate file
 </script>
 </body>
</html>

Installing via npm


You can also install React using npm by doing the following:

npm install --save react react-dom

To use React in your JavaScript project, you can do the following:

var React = require('react');
var ReactDOM = require('react-dom');
ReactDOM.render(<App />, ...);

Installing via Yarn


Facebook released its own package manager named Yarn, which can also be used to install React. After installing Yarn you just need to run this command:

yarn add react react-dom

You can then use React in your project in exactly the same way as if you had installed React via npm.


Conclusion

In this page (written and validated by ) you learned about React Installation or Setup . What's Next? If you are interested in completing React tutorial, your next topic will be learning about: React Hello World with Stateless Functions.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.