React / 3 MIN READ
Create React App 2
The old standby
From the original Fervor library. Examples may use older package versions.
Creating a React App with VS Code
Introduction
Welcome to FrOnt3nd Tutorials! In this tutorial, we’ll guide you through the process of creating and running a React app using Visual Studio Code (VS Code). React is a popular JavaScript library for building user interfaces, and VS Code is a powerful code editor that offers great tools for web development.
Table of Contents
Install Node.js
Before you start, make sure you have Node.js installed. If not, you can download and install it from the official website: Node.js Download
Install VS Code
If you haven’t already, download and install Visual Studio Code (VS Code) from the official website: VS Code Download
Install Required Extensions
Once you have VS Code installed, you’ll need to install some extensions to enhance your React development experience. Follow these steps:
- Open VS Code.
- Click on the Extensions icon on the left-hand side of the screen or press Ctrl+Shift+X (Windows/Linux) or Cmd+Shift+X (Mac) to open the Extensions sidebar.
- Search for and install the following extensions:
- Node.js Extension Pack: Provides Node.js debugging and other tools for VS Code.
- JavaScript (ES6) code snippets: Provides useful code snippets for writing JavaScript code.
- Reactjs code snippets: Provides useful code snippets for writing React code.
Create a New React App
- Open the terminal in VS Code by clicking on “Terminal” in the top menu bar and selecting “New Terminal.”
- Run the following command to create a new React app named “my-app”:
This command will create a new directory named “my-app” with all the necessary files and dependencies to start your React app.npx create-react-app my-app
Open the Project in VS Code
- In VS Code, click on “File” in the top menu bar and select “Open Folder.”
- Navigate to the “my-app” directory that was created in the previous step and click “Open.”
Run Your React App
- In the terminal, navigate to the “my-app” directory by running the following command:
cd my-app - Start a development server by running the following command:
This command will start a development server and open your React app in a new browser window.npm start
Get Live Feedback
You can use tools like LiveReload or React Hot Loader to get live feedback on your app as you make changes to your code.
Using LiveReload
- Install the LiveReload browser extension.
- Add the following code to the bottom of your public/index.html file:
This enables live reloading of your app.<script src="//localhost:35729/livereload.js"></script>
Using React Hot Loader
- Install React Hot Loader as a dependency by running the following command:
npm install react-hot-loader - Add the following code to your webpack.config.js file:
module.exports = { // ... module: { rules: [ // ... { test: /\.(js|jsx)$/, use: ["babel-loader", "react-hot-loader/webpack"], exclude: /node_modules/ } ] }, resolve: { alias: { "react-dom": "@hot-loader/react-dom" } } };
With these steps, you should be able to create, run, and get live feedback on your React app using Visual Studio Code.
Conclusion
Congratulations! You’ve successfully learned how to create and run a React app using Visual Studio Code. Keep exploring React’s features, building components, and enhancing your web development skills.
For more advanced topics and in-depth learning, refer to React’s official documentation and other resources.