Getting Started with React JS
By Codes With Pankaj
In this tutorial, we’ll learn how to set up React and create a simple app that prints “Hello World” on the screen.
What You Need Before Starting
Basic Knowledge: Familiarity with JavaScript and HTML.
Tools to Install:
Node.js (comes with npm).
A text editor like VS Code.
Step-by-Step: Setting Up React
Step 1: Install Node.js
Download Node.js from the official website: https://nodejs.org/.
Install Node.js and verify it by running the following commands in the terminal:
If installed correctly, these commands will display the versions of Node.js and npm.
Step 2: Create a React App
React provides a tool called Create React App to set up everything automatically.
Open your terminal and run the following command:
This command will create a folder named hello-world-app with all the necessary files.
The process might take a few minutes as it downloads dependencies.
Navigate to your project folder:
Step 3: Start the React App
To start the React development server:
This will open your app in the browser at
http://localhost:3000/
.By default, you’ll see the React logo and some boilerplate text.
Write Your First "Hello World" App
Open the project folder in your text editor (VS Code).
Locate the file
src/App.js
.Replace the code inside
App.js
with the following:Save the file.
Go back to your browser. It will automatically refresh and display:
How It Works
React Components: The
App
function is a React component that returns HTML (written as JSX).JSX: Lets you write HTML inside JavaScript, making it easy to design the UI.
Live Reloading: Any changes you make in the code automatically update the browser.
Wrapping Up
You’ve successfully installed React and printed your first “Hello World” using React JS! 🎉
Last updated