Web Development · React JS
React JS Basics Explained for Complete Beginners
Quick summary — React JS basics
React JS basics come down to a few ideas: build the UI from components, describe each one with JSX, pass data down with props, keep changing data in state with useState, handle events like clicks, and run side effects such as API calls with useEffect. Master these and you can build real interactive pages.
In this guide you will learn:
- Components and JSX — how React describes UI.
- Props and state — how data flows and changes.
- Events, lists and effects — making pages interactive.
- A first project plan — with templates and a checklist.
- Interview basics — React questions beginners face.
SECTION 01Components and JSX: how React describes UI
In React, a component is a JavaScript function that returns what should appear on screen. JSX lets you write that output in a syntax that looks like HTML, which React turns into real page elements. You will write every React screen this way, from a single button to a full dashboard, so it is worth getting comfortable with the syntax before moving on.
| Idea | Example | Rule to remember | Common beginner mistake |
|---|---|---|---|
| Component | function Welcome() { return <h1>Hi</h1>; } | Name starts with a capital letter | Naming it welcome() in lowercase |
| JSX expressions | <p>{user.name}</p> | Curly braces hold JavaScript | Writing if statements directly inside JSX |
| Attributes | <img src={url} alt="logo" /> | Use className, not class | Using class="..." |
| One parent | return <>...</> | Return a single root element | Returning two siblings without a wrapper |
// App.jsx (created with: npm create vite@latest my-app -- --template react)
function Welcome({ name }) {
return <h1 className="title">Hello, {name}!</h1>;
}
export default function App() {
return (
<>
<Welcome name="Asha" />
<Welcome name="Ravi" />
</>
);
}
function Status({ isOnline }) {
return (
<p>
{isOnline ? "Online" : "Offline"}
{isOnline && <span> ●</span>}
</p>
);
}
// ternary for either/or, && for show-or-hide
SECTION 02Props and state: how data flows and changes
Props and state are the two kinds of data in React. Props come from outside and are read-only. State belongs to the component and can change, and every change re-renders the component. Most beginner bugs in React come from mixing these two up, so read the table slowly and try each example in a fresh Vite project.
| Props | State | Example | |
|---|---|---|---|
| Who owns it | The parent component | The component itself | A Cart owns items; an Item gets props |
| Can it change? | Not by the child | Yes, through the setter | setCount(count + 1) |
| How to create | <Item price={499} /> | const [count, setCount] = useState(0) | Counter starts at 0 |
| When UI updates | When the parent passes new props | When the setter is called | Clicking a button updates a count |
import { useState } from "react";
export default function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Add</button>
<button onClick={() => setCount(0)}>Reset</button>
</div>
);
}
import { useState } from "react";
function Item({ name, onAdd }) {
return <button onClick={() => onAdd(name)}>Add {name}</button>;
}
export default function Cart() {
const [items, setItems] = useState([]);
const add = (name) => setItems([...items, name]); // new array, not push
return (
<div>
<Item name="Pen" onAdd={add} />
<Item name="Book" onAdd={add} />
<p>Cart: {items.join(", ") || "empty"}</p>
</div>
);
}
SECTION 03Events, lists and effects: making pages interactive
Real apps respond to clicks and typing, show lists of data and load information from servers. These three patterns cover most beginner projects. Practise each pattern in a tiny component of its own before combining them; that way, when something breaks, you know exactly which part to look at.
| Pattern | React tool | Example | Remember |
|---|---|---|---|
| Handle events | onClick, onChange, onSubmit | <input onChange={e => setText(e.target.value)} /> | Pass a function, do not call it |
| Render lists | array.map() | items.map(i => <li key={i.id}>...) | Each item needs a stable key |
| Forms | Controlled inputs | value={text} with onChange | Call e.preventDefault() on submit |
| Load data | useEffect + fetch | Fetch users after first render | Set the dependency array correctly |
import { useState } from "react";
export default function Todos() {
const [text, setText] = useState("");
const [todos, setTodos] = useState([]);
function handleSubmit(e) {
e.preventDefault();
if (!text.trim()) return;
setTodos([...todos, { id: Date.now(), text }]);
setText("");
}
return (
<form onSubmit={handleSubmit}>
<input value={text} onChange={(e) => setText(e.target.value)} />
<button>Add</button>
<ul>{todos.map((t) => <li key={t.id}>{t.text}</li>)}</ul>
</form>
);
}
import { useEffect, useState } from "react";
export default function Users() {
const [users, setUsers] = useState([]);
const [error, setError] = useState(null);
useEffect(() => {
fetch("https://jsonplaceholder.typicode.com/users")
.then((r) => r.json())
.then(setUsers)
.catch(() => setError("Could not load users"));
}, []); // empty array: run once after first render
if (error) return <p>{error}</p>;
return <ul>{users.map((u) => <li key={u.id}>{u.name}</li>)}</ul>;
}
SECTION 04First React project templates
Use these templates to plan and finish your first React project. Pick a topic you personally care about — cricket scores, recipes or movies — because you will spend more time on a project you enjoy.
First React Project: Movie Watchlist
Components:
App → SearchBar, MovieList → MovieCard, Watchlist
State:
query (string), results (array), watchlist (array)
Features:
☐ Search movies from a public API
☐ Show results as cards
☐ Add/remove from watchlist
☐ Save watchlist in localStorage
☐ Loading and error messages
Deploy: Netlify / Vercel / GitHub Pages
Component Map (draw before coding)
App
├── Header
├── SearchBar props: onSearch
├── MovieList props: movies, onAdd
│ └── MovieCard props: movie, onAdd
└── Watchlist props: items, onRemove
State lives in App and flows down as props.
React Basics Checklist
☐ Create a project with Vite
☐ Write components with JSX
☐ Pass and use props
☐ useState for changing data
☐ Handle click and form events
☐ Render lists with keys
☐ Fetch data with useEffect
☐ Show loading and error states
☐ Deploy the app
SECTION 05Tips for learning React as a beginner
These habits help React make sense faster:
- Learn JavaScript first — arrays, objects, arrow functions and map make React much easier.
- Draw the component tree — plan components and where state lives before coding.
- Keep state minimal — store only what changes; calculate the rest during render.
- Use React DevTools — inspect props and state in the browser while debugging.
- Build, then rebuild — make the same small app twice to lock in the patterns.
SECTION 06Interview Q&A — React JS basics
Q1What is React?
A JavaScript library for building user interfaces from reusable components. It updates the page efficiently when data changes.
Q2What is JSX?
A syntax extension that lets you write HTML-like code inside JavaScript. Build tools convert it into regular JavaScript calls.
Q3What is the difference between props and state?
Props are read-only data passed from a parent. State is data a component manages itself and can change, causing a re-render.
Q4Why do list items need keys?
Keys let React identify which items changed, were added or removed, so it can update the list correctly and efficiently.
Q5What does useEffect do?
It runs side effects, such as fetching data or setting up subscriptions, after rendering. The dependency array controls when it runs again.
SECTION 07Test yourself — React JS basics quiz
Five questions. No sign-up.
0 / 5Pick an answer to see why it is right or wrong.
SECTION 08Frequently asked questions
Is React easy for beginners?
React is beginner-friendly once you know JavaScript basics. The core ideas — components, props, state and effects — are few and reusable.
What should I learn before React?
HTML, CSS and JavaScript fundamentals, especially arrays, objects, functions, arrow functions and fetch.
Is React a framework or a library?
React is a library for building user interfaces. Frameworks such as Next.js build on top of it.
How long does it take to learn React basics?
With solid JavaScript, many learners grasp the basics in a few weeks of regular practice and small projects.
Can I get a job with only React?
Frontend roles usually expect React plus strong HTML, CSS and JavaScript, Git, and often some API and testing knowledge.
SECTION 09Related reads
Classroom & online · Noida
Go from frontend to full stack
Our Python Training Course covers Python, web frameworks, REST APIs and SQL — the backend skills that pair with React for full stack work.
Talk to a counsellor for current fees- Python and web frameworks
- REST APIs and SQL
- Mock interviews
- Weekday & weekend batches