MOCKSTACKS
EN
Questions And Answers

More Tutorials









React Setting Up React Environment


We want to be able to compile below component and render it in our webpage

Filename: src/index.jsx

import React from 'react';
import ReactDOM from 'react-dom';
class ToDo extends React.Component {
 render() {
 return (<div>I am working</div>);
 }
}
ReactDOM.render(<ToDo />, document.getElementById('App'));

Install all dependencies


# install react and react-dom
$ npm i react react-dom --save
# install webpack for bundling
$ npm i webpack -g
# install babel for module loading, bundling and transpiling
$ npm i babel-core babel-loader --save
# install babel presets for react and es6
$ npm i babel-preset-react babel-preset-es2015 --save

Configure webpack


Create a file webpack.config.js in the root of your working directory
Filename: webpack.config.js

module.exports = {
 entry: __dirname + "/src/index.jsx",
 devtool: "source-map",
 output: {
 path: __dirname + "/build",
 filename: "bundle.js"
 },
 module: {
 loaders: [
 {test: /\.jsx?$/, exclude: /node_modules/, loader: "babel-loader"}
 ]
 }
}


Conclusion

In this page (written and validated by ) you learned about React Setting Up React Environment . What's Next? If you are interested in completing React tutorial, your next topic will be learning about: React Using with Flow.



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.