Welcome to the first part of our beginner-friendly React series! ๐
In this post, weโll take a hands-on look at what React is, why itโs useful, and how to build your very first React component.
๐ง What is React?
React is a JavaScript library for building user interfaces. It helps developers build fast and interactive UIs using a component-based architecture.
You can think of it as a LEGO set for websites โ each block (component) does one thing well and can be reused wherever you want.
React was created by Facebook and is now maintained by Meta and the open-source community.
๐ Why Learn React?
React is:
- ๐ Declarative โ You describe what you want, not how to do it.
- ๐งฑ Component-Based โ You break UIs into small, manageable, and reusable pieces.
- โก Fast & Efficient โ Thanks to its virtual DOM and update diffing.
- ๐ Widely Used โ From startups to big tech, itโs everywhere.
๐ ๏ธ Setting Up Your First React Project
Weโll use Vite for a fast, modern setup. You can also use Create React App (CRA), but Vite is lighter and preferred for new projects.
โ Prerequisites
- Node.js installed (version 16+ recommended)
- A terminal and a code editor like VS Code
๐งช Step-by-Step (Vite)
- Create a new project
npm create vite@latest my-first-react-app -- --template react
cd my-first-react-app
- Install dependencies
npm install
- Run the app
npm run dev
- Open your browser and go to
http://localhost:5173
You should see the default Vite + React starter screen!
๐งฉ Your First Component
Letโs build a basic โHello Worldโ component.
Replace the contents of App.jsx with:
function App() {
return (
<div>
<h1>Hello, React!</h1>
<p>This is my very first React component.</p>
</div>
);
}
export default App;
Explanation:
- The
Appfunction is a component. - It returns JSX, a syntax extension that lets you write HTML inside JavaScript.
-
export default Appmakes it available to be rendered in the app.
๐ฆ What is JSX?
JSX stands for JavaScript XML.
It's not valid HTML or JavaScript โ it's a hybrid that looks like HTML but works inside JavaScript. It gets compiled to regular JavaScript by tools like Babel.
Example:
<h1>Hello World</h1>
is compiled into:
React.createElement('h1', null, 'Hello World');
โ๏ธ Challenge for You
Try modifying your App component:
- Change the text to introduce yourself.
- Add an image using
<img>tag. - Try nesting another component (weโll learn more next time).
โ Summary
- React helps you build modern user interfaces with reusable components.
- JSX is a key part of writing React code.
- You created your first project using Vite.
- You wrote your first component!
๐ Whatโs Next?
In Part 2, weโll dive deeper into components and props โ the building blocks of scalable React apps.
Until then, keep tinkering with your new project! ๐ป
Top comments (0)