Introduction to React
React is a JavaScript library for building user interfaces out of small, reusable pieces called components. You describe what the screen should look like, and React keeps the page in sync with your data.
On this page · 5 min · Beginner
On this page
- Learning objectives
- Explanation
- Syntax
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Beginner
- Updated
- Oct 28, 2026
Related tutorials
Learning objectives#
- Explain what React is and what problem it solves
- Understand components, props and state at a high level
- Know how React updates the page efficiently
- Read a first React component
Explanation#
In plain JavaScript you change the page step by step: find an element, change its text, add a class. As apps grow, keeping every element in sync with the data becomes the hardest part.
React is declarative: you write a function that returns what the UI should look like for the current data. When the data changes, React works out the minimal DOM changes for you.
Everything is a component — a function that returns markup written in JSX. Components receive inputs (props), keep their own changing data (state) and are combined into bigger components.
React compares the new output with the previous one (reconciliation) and updates only what changed, so you never touch the DOM directly.
React was created at Facebook (Meta) and is used by Netflix, Airbnb, Instagram and countless companies. React itself only handles the UI; routing, data fetching and builds come from tools like React Router and Vite.
Syntax#
function Welcome({ name }) {
return <h1>Hello, {name}!</h1>;
}
Code example: A first interactive component#
import { useState } from 'react';
function Greeting({ name }) {
return <h1>Hello, {name}!</h1>;
}
export default function App() {
const [likes, setLikes] = useState(0);
return (
<main>
<Greeting name="Asha" />
<p>This page has {likes} likes.</p>
<button onClick={() => setLikes(likes + 1)}>👍 Like</button>
</main>
);
}
The page shows “Hello, Asha!”, “This page has 0 likes.” and a Like button. Each click increases the number; React updates only that text, not the whole page.
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- Greeting is a component: a function that receives props (name) and returns JSX.
- App uses Greeting like an HTML tag: <Greeting name="Asha" />.
- useState(0) gives App a piece of state, likes, and a function to change it.
- Clicking the button calls setLikes; React re-runs App and updates the changed text.
Real-world use case#
An online shop builds a ProductCard component once and reuses it hundreds of times on listing, search and wishlist pages, each time with different props.
Common mistakes#
document.getElementById(...).innerText = ... fights with React. Change state and let React update the DOM.
React is the view layer. You add a router, data fetching and a build tool around it.
<greeting /> is treated as an HTML tag. Components must start with a capital letter.
Best practices#
- Think in components: split the UI into small pieces
- Keep components pure: same props → same output
- Change data, not the DOM
- Learn modern JavaScript first
Remember this#
UI = function(data). Change the data; React updates the screen.
Component = function that returns JSX.
Props come in; state lives inside.
Practice exercise#
Your task: Write a component ProfileCard that receives name and city props and renders them in an <article> with an <h2> and a <p>.
Need a hint?
Show solution
export default function ProfileCard({ name = 'Ravi', city = 'Pune' }) {
return (
<article>
<h2>{name}</h2>
<p>Lives in {city}</p>
</article>
);
}
// <ProfileCard name="Asha" city="Bengaluru" />
Mini quiz#
What does “declarative” mean in React?
Want more? Practise all React MCQs · React interview questions
My notes#
Saved in this browser.