Welcome to the React.js Masters course! In this section, we will guide you through the process of setting up your development environment and creating your first React application.
Before you begin, ensure you have the following prerequisites:
To create a new React application, we will use the Create React App tool, which sets up everything you need to start coding in React.
For detailed installation instructions, refer to the Installation Guide.
Create a new React application by running:
npx create-react-app my-first-app
Replace my-first-app
with the name of your project. This command will create a new directory with the same name, initialize a new React project, and install the required dependencies.
Change into your project directory:
cd my-first-app
Start the development server to see your new React application in action:
npm start
This command will open your default web browser and navigate to http://localhost:3000, where you will see the default React welcome page.
After creating your project, you will see a file structure like this:
my-first-app/ ├── node_modules/ ├── public/ │ ├── index.html │ └── favicon.ico ├── src/ │ ├── App.css │ ├── App.js │ ├── App.test.js │ ├── index.css │ ├── index.js │ └── ... logo.svg, reportWebVitals.js, setupTests.js ├── .gitignore ├── package.json ├── README.md └── yarn.lock or package-lock.json
This structure serves as a guide to understand the typical file structure of a React project. It provides insight into the purpose of each directory and file, aiding developers in navigating and managing their projects effectively.
Now, let's create a simple React component. Open src/App.js and replace its content with the following:
import React from 'react';
import './App.css';
function App() {
return (
<div className="App">
<h1>Hello world</h1>
</div>
);
}
export default App;
Save the file, and you should see the changes reflected in your browser.
Congratulations! You've successfully set up your development environment and created your first React application.
This guide provided an overview of setting up a React development environment and creating your first application. Ensure you are comfortable with these steps before moving on to more advanced topics.