React Component Nesting and Reusability Explained – A Beginner's Guide 2026
React.js is a popular JavaScript library used to create
interactive and modern websites. Many beginners want to learn React but feel
confused about how to install it and start their first project. Before writing
React code, we need a proper development environment.
In this tutorial, you will learn how to create a React app
using Vite from the beginning. We will cover the basic requirements,
installation process, project structure, important features, advantages,
disadvantages and practical code examples.
React.js is an open-source JavaScript library used to build
user interfaces, especially for websites and web applications. It was
originally developed at Facebook (now Meta) to make it easier to manage complex
and interactive website interfaces.
React allows developers to divide a website into smaller
parts called components. Each component can manage its own structure and
behaviour. For example login , navigation bar ,website header form and footer
can all be created as separate components.
One important concept in React is JSX. JSX allows
developers to write HTML-like syntax inside JavaScript code. It makes the user
interface easier to understand and maintain.
React also provides features such as reusable components,
props, state and event handling. These features help developers create
applications with less repeated code.
For example, when a user clicks a button, React can update
the required part of the interface without manually changing the entire
webpage.
React is useful for beginners as well as professional
developers because it supports small projects and large applications.
Before creating a React application, install Node.js on
your computer.
Open Command Prompt or the terminal and run:
node -v
To check npm, run:
npm -v
If both commands display version numbers, Node.js and npm
are available.
First, open your terminal and execute this command:
npm create vite@latest my-react-app -- --template react
Move into your project folder:
cd my-react-app
Install the required packages:
npm install
This command downloads the dependencies needed to run your
React application.
Now run:
npm run dev
Vite starts a local development server. Open the local URL
displayed in your terminal, usually:
http://localhost:5173/
You should now see your React application running in your
browser.
Open the src/App.jsx file and replace its existing code
with:
function App() {
return (
<div>
<h1>Hello, React!</h1>
<p>Welcome to my first React project.</p>
</div>
);
}
export default App;
Explanation:
Now create a simple counter application.
import { useState } from "react";
function App() {
const [count, setCount] = useState(0);
return (
<div>
<h1>React Counter</h1>
<h2>Count: {count}</h2>
<button
onClick={() => setCount(count + 1)}>
Increase
</button>
</div>
);
}
export default App;
Explanation:
When your application is ready, run:
npm run build
Vite creates an optimized production version of your
project in the dist folder.
To preview the production build locally, run:
npm run preview
Congratulations! You have created your first React
application using Vite.
4. Frequently Asked Questions (FAQs)
Q1. What is Vite in React?
Vite is a frontend build tool used to create and develop
React applications. It provides a development server and production build
tools.
Q2. Is Vite better than Create React App?
Vite is a modern development tool that offers a fast
development experience. Create React App has been deprecated, and React's
documentation no longer recommends it for new applications.
Q3. Is Node.js required for React?
For a local React project created using Vite, Node.js is
required to run the development tools and npm commands.
Q4. Is React free to use?
Yes. React is open-source software and can be used for
personal, educational and commercial projects under its license.
Q5. Can beginners learn React?
Yes. Beginners can learn React after understanding basic
HTML, CSS and JavaScript concepts.
Q6. What is the use of npm in React?
npm is a package manager used to install, update and manage
the packages required by a React project.
Q7. What is the difference between React and Vite?
React is a JavaScript library for building user interfaces,
whereas Vite is a development and build tool used to create and run frontend
projects.
Q8. How do I run a React project?
Open the project folder in your terminal, run npm install
and then execute npm run dev to start the development server.
Q9. What is JSX in React?
JSX is a syntax extension that allows developers to write
HTML-like code inside JavaScript.
Q10. Can I use VS Code for React development?
Yes. Visual Studio Code is a popular code editor for
creating, editing and managing React projects.
Creating a React application using Vite is a simple and
practical way to begin learning modern frontend development. In this tutorial,
we explored React.js, its history, important features, advantages,
disadvantages and working process.
We also learned how to check Node.js and npm, create a
React project, install dependencies, start the development server and write our
first React components.
The best way to understand React is to practise regularly.
Start with small projects such as a counter, calculator, to-do list or simple
shopping page. As your knowledge improves, you can move towards more advanced
applications.
Keep learning, keep practising and build your own projects
with React!
Thank you for visiting Web Designing Theory. Keep learning
and growing with us.
Visit our blog for more web development tutorials:
https://webdesigningtheory.blogspot.com/
Comments
Post a Comment