In this blog, you will see how to set up development environment for React.

React

React is a declarative, efficient, and flexible JavaScript library for building user interfaces.

Prerequisites

Node.js

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.

NPM

Node Package Manager (NPM) is used to install the packages that you want to use, and provides a useful interface to work with them.

Install Node.js and NPM

Visual Studio Code

Install VS Code

Steps Involved

  1. var config = {
  2. entry: './main.js',
  3. output: {
  4. path: '/',
  5. filename: 'index.js',
  6. },
  7. devServer: {
  8. inline: true,
  9. port: 8080
  10. },
  11. module: {
  12. loaders: [
  13. {
  14. test: /\.jsx?$/,
  15. exclude: /node_modules/,
  16. loader: 'babel-loader',
  17. query: {
  18. presets: ['es2015', 'react']
  19. }
  20. }
  21. ]
  22. }
  23. }
  24. module.exports = config;
Open index.html file and add the below code snippet.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>React App</title>
  6. </head>
  7. <body>
  8. <div id="app"></div>
  9. <script src="index.js"></script>
  10. </body>
  11. </html>
Open App.jsx file and add the below code snippet.
  1. import React from 'react';
  2. class App extends React.Component {
  3. render() {
  4. return (
  5. <div>
  6. Hello World!!!
  7. </div>
  8. );
  9. }
  10. }
  11. export default App;
Open main.js file and add the below code snippet.
  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import App from './App.jsx';
  4. ReactDOM.render(<App />, document.getElementById('app'));
Open package.json file and update the scripts (highlighted).
  1. {
  2. "name": "helloworld",
  3. "version": "1.0.0",
  4. "description": "helooworld",
  5. "main": "index.js",
  6. "scripts": {
  7. "start": "webpack-dev-server"
  8. },
  9. "author": "",
  10. "license": "ISC",
  11. "dependencies": {
  12. "react": "^15.4.2",
  13. "react-dom": "^15.4.2",
  14. "webpack": "^2.2.1",
  15. "webpack-dev-server": "^2.4.1"
  16. }
  17. }

Testing

Run the following command to start the Server. Open the browser and type http://localhost:8080/

npm start



Summary

In this blog, you have seen how to set up development environment for React.