ЁЯФ╣ ReactJS рдПрдХ JavaScript рд▓рд╛рдЗрдмреНрд░реЗрд░реА рд╣реИ рдЬреЛ рдпреВрдЬрд╝рд░ рдЗрдВрдЯрд░рдлреЗрд╕ (User Interface) рдпрд╛ UI рдмрдирд╛рдиреЗ рдХреЗ рд▓рд┐рдП рдкреНрд░рдпреЛрдЧ рд╣реЛрддреА рд╣реИред
тЬЕ React рд╕рд┐рд░реНрдл UI рдмрдирд╛рддрд╛ рд╣реИ, рдпрд╛рдиреА рдпрд╣ рдЖрдкрдХреА рд╡реЗрдмрд╕рд╛рдЗрдЯ рдпрд╛ рд╡реЗрдм рдРрдк рдХрд╛ "View" Layer рд╕рдВрднрд╛рд▓рддрд╛ рд╣реИред
React is a JavaScript library used to build the Graphical User Interface (GUI) of web applications.
It is mainly used to create Single Page Applications (SPA) and mobile applications.
The structure of a React application is built using components, which are of two types:
React works using some important technologies and concepts:
render()
componentDidMount()
shouldComponentUpdate()
componentWillUnmount()
Year | Event |
---|---|
2011 | React рдХрд╛ рдкрд╣рд▓рд╛ version Facebook рдореЗрдВ internally use рд╣реБрдЖред |
2013 | React рдХреЛ open-source рдХрд┐рдпрд╛ рдЧрдпрд╛ред |
2015 | Functional & Class Components рдЖрдПред |
2016 | React 15 рд▓реЙрдиреНрдЪ рд╣реБрдЖред |
2017 | React 16 - Fiber Architecture launchред |
2019 | React Hooks (`useState`, `useEffect`) рдЖрдПред |
2023 | React 18 - Concurrent Mode, Streamingред |
2024/25 | ЁЯЪА React 19 тАУ Compiler-based Renderingред |
ЁЯУМ Feature | тЪб рдлрд╛рдпрджрд╛ |
---|---|
тЬЕ Component-based | Code reusable рд╣реЛрддрд╛ рд╣реИ, рд╣рд░ UI рд╣рд┐рд╕реНрд╕рд╛ рдПрдХ рдЫреЛрдЯрд╛ component рд╣реЛрддрд╛ рд╣реИред |
тЪб Virtual DOM | React рддреЗрдЬрд╝ рд╣реЛрддрд╛ рд╣реИ рдХреНрдпреЛрдВрдХрд┐ рдпреЗ browser рдореЗрдВ DOM рдХреЛ directly рдирд╣реАрдВ рдмрджрд▓рддрд╛ред |
ЁЯЪА Fast Performance | DOM рдХреЛ memory рдореЗрдВ compare рдХрд░рддрд╛ рд╣реИ, рдЬрд┐рд╕рд╕реЗ fast rendering рд╣реЛрддреА рд╣реИред |
ЁЯОп JSX | HTML рдФрд░ JavaScript рдХреЛ рдПрдХ рд╕рд╛рде рд▓рд┐рдЦрдиреЗ рдХреА рд╕реБрд╡рд┐рдзрд╛ рджреЗрддрд╛ рд╣реИред |
ЁЯФД One-Way Data Binding | Data рдПрдХ рд╣реА direction рдореЗрдВ flow рдХрд░рддрд╛ рд╣реИред |
ЁЯФМ Hooks Support | Functional components рдореЗрдВ state рдФрд░ lifecycle methods use рдХрд░ рд╕рдХрддреЗ рд╣реИрдВред |
ЁЯзй Ecosystem | Redux, React Router, Axios рдЖрджрд┐ рд╕реЗ integration рдЖрд╕рд╛рди рд╣реИред |
ЁЯМН SEO Friendly | React SSR (Server Side Rendering) рдХреЛ support рдХрд░рддрд╛ рд╣реИред |
ЁЯТ╝ Job Opportunities | React developers рдХреА demand high рд╣реИред |
Version | Highlights |
---|---|
React 16 | Error Boundaries, Fragments |
React 17 | Upgrade with no breaking changes |
React 18 | Automatic Batching, Concurrent Mode |
тЬЕ React 19 | ЁЯФе New Compiler, Server Actions, use() Hook, Lazy Loading, Streaming |
ЁЯФ╣ Library рдПрдХ code collection рд╣реЛрддреА рд╣реИ рдЬрд┐рд╕рдореЗрдВ рдкрд╣рд▓реЗ рд╕реЗ рд▓рд┐рдЦреЗ рд╣реБрдП functions, methods рдФрд░ tools рд╣реЛрддреЗ рд╣реИрдВред рдпреЗ рдЖрдкрдХреЗ development рдХреЛ рдЖрд╕рд╛рди рдмрдирд╛рддреЗ рд╣реИрдВред
ЁЯУМ Developer library рдХреЛ рдЬрд░реВрд░рдд рдкрдбрд╝рдиреЗ рдкрд░ call рдХрд░рддрд╛ рд╣реИ тАУ control developer рдХреЗ рдкрд╛рд╕ рд╣реЛрддрд╛ рд╣реИред
ЁЯФ╣ Framework рдПрдХ рдкреВрд░рд╛ structure рд╣реЛрддрд╛ рд╣реИ рдЬрд┐рд╕рдореЗрдВ rules, patterns рдФрд░ flow predefined рд╣реЛрддрд╛ рд╣реИред рдЖрдкрдХреЛ рдЙрд╕реА structure рдХреЗ рдЕрдиреБрд╕рд╛рд░ рдХрд╛рдо рдХрд░рдирд╛ рд╣реЛрддрд╛ рд╣реИред
ЁЯУМ Framework рдЖрдкрдХреЗ code рдХреЛ control рдХрд░рддрд╛ рд╣реИ тАУ рдпреЗ decide рдХрд░рддрд╛ рд╣реИ рдХрд┐ рдЖрдкрдХрд╛ code рдХреИрд╕реЗ рдЪрд▓реЗрдЧрд╛ред
ЁЯФз Point | ЁЯУЪ Library | ЁЯПЧя╕П Framework |
---|---|---|
Control | Developer | Framework |
Code Flow | Developer library рдХреЛ call рдХрд░рддрд╛ рд╣реИ | Framework рдЖрдкрдХреЗ code рдХреЛ call рдХрд░рддрд╛ рд╣реИ |
Flexibility | рдЬреНрдпрд╛рджрд╛ | рдХрдо |
Examples | React, jQuery, Axios | Angular, Laravel, Django |
Size | Chhoti | Badi |
Learning Curve | Easy | Tough |
Example | Library | Framework |
---|---|---|
Kitchen | рдЖрдкрдиреЗ mixer grinder рд▓рд┐рдпрд╛ тАУ рдЬрдм рдЬрд░реВрд░рдд рд╣реЛ, use рдХрд░реЛ | рдЖрдкрдиреЗ chef рд░рдЦрд╛ тАУ рдкреВрд░рд╛ рдХрд╛рдо chef рдЕрдкрдиреЗ рд╣рд┐рд╕рд╛рдм рд╕реЗ рдХрд░реЗрдЧрд╛ |
import React from 'react';
function App() {
return <h1>Hello, World!</h1>;
}
ЁЯСЙ Aap React ko jab chahein tab use kar sakte hain тАУ control aapke paas hai.
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
title = 'MyApp';
}
ЁЯСЙ Yahan Angular batata hai ki component kaise banega тАУ control framework ke paas haiред
React рдПрдХ library рд╣реИ, рдЬреЛ UI рдмрдирд╛рдиреЗ рдХреЗ рд▓рд┐рдП use рд╣реЛрддреА рд╣реИред рд▓реЗрдХрд┐рди рдЬрдм рдЖрдк uske saath routing, state management рдЖрджрд┐ рдЬреЛрдбрд╝рддреЗ рд╣реИрдВ рддреЛ рдпреЗ ek framework рдЬреИрд╕рд╛ рдмрди рдЬрд╛рддрд╛ рд╣реИред
Criteria | Library | Framework |
---|---|---|
Control | Developer | Framework |
Use | Specific Function | Complete Structure |
Flexibility | High | Low |
Example | React, jQuery | Angular, Django |
To work with React, we need to set up our environment with Node.js, a code editor like VS Code, and a project setup tool (CRA or Vite).
node -v
npm -v
Method | Tool | Best For |
---|---|---|
Traditional | Create React App (CRA) | Beginners & Learning |
Modern | Vite | Fast builds & advanced devs |
npx create-react-app my-app
cd my-app
npm start
ЁЯЪА Opens at http://localhost:3000
project
cd/
D:
cd project
npm create vite
y
and press EntersinglePage
cd singlePage
npm install
code .
code
command is available)
npm run dev
Your first React app using Vite is ready and running!
npm create vite@latest
cd my-app
npm install
npm run dev
ЁЯЪА Opens at http://localhost:5173 (or next available port)
public/
тАУ static files like index.htmlsrc/
тАУ all your React componentsApp.js
тАУ main componentindex.js
тАУ entry pointJab aap npm install
ya yarn install
chalate ho, to ye folder automatic create hota hai.
Static files jo browser ko directly serve hote hain (bundle ke through nahi).
index.html
тАФ main HTML file jisme React app mount hota hai (usually <div id="root"></div>
).favicon.ico
, static images, manifest, robots.txt waqera.Yeh sabse important folder hai тАФ aapka main application code yahin hota hai.
App.js
) тАФ main React component.index.js
) тАФ entry point: ReactDOM.render / createRoot se <App />
mount hota hai.Git ko batata hai kaunse files/folders commit nahi karne chahiye.
# example .gitignore
node_modules/
dist/
build/
.env
.DS_Store
Secrets (jaise API keys) ko .env
me rakhte hain aur is file ko git se ignore karte hain.
Project ka configuration aur "shopping list" тАФ dependencies aur scripts yahan defined hote hain.
{
"name": "my-react-app",
"version": "1.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"start": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
Dependencies ke exact versions lock karne ke liye тАФ taaki sab developers same versions use karein.
Bundler/Dev server configuration: aliases, plugins, optimization settings, etc.
my-react-app/
тФЬтФА node_modules/
тФЬтФА public/
тФВ тФЬтФА index.html
тФВ тФФтФА favicon.ico
тФЬтФА src/
тФВ тФЬтФА assets/
тФВ тФЬтФА App.jsx
тФВ тФЬтФА App.css
тФВ тФЬтФА index.css
тФВ тФФтФА main.jsx
тФЬтФА .gitignore
тФЬтФА package.json
тФФтФА package-lock.json
JSX stands for JavaScript XML.
It allows us to write HTML-like code inside JavaScript.
JSX makes it easier to write and add HTML in React applications.
Welcome to React JSX
className
instead of class
.{}
.JSX ka full form hai JavaScript XML. Ye ek special syntax hai jisme hum JavaScript ke andar HTML jaisa code likh sakte hain.
function App() {
return (
<div>
<h1>Hello World ЁЯСЛ</h1>
<p>This is JSX in React</p>
</div>
);
}
export default App;
Yaha HTML jaisa lag raha hai, lekin ye actually JSX hai.
Curly braces { }
ke andar JavaScript expressions likh sakte ho.
const name = "Praveen";
const age = 22;
function App() {
return (
<div>
<h2>Hello, {name}!</h2>
<p>Your age is {age}</p>
<p>2 + 2 = {2 + 2}</p>
</div>
);
}
class
ki jagah className
likhna padta hai.<img />
).Comparison table тАФ copy the right column into a React component's style={{ ... }}
object.
Normal CSS (file / <style>) | React Inline Style (JSX) |
---|---|
color: red;
|
style={{ color: "red" }}
|
background-color: yellow;
|
style={{ backgroundColor: "yellow" }}
|
font-size: 20px;
|
style={{ fontSize: "20px" }}
|
margin-top: 10px;
|
style={{ marginTop: "10px" }}
|
padding: 5px 10px;
|
style={{ padding: "5px 10px" }}
|
border: 2px solid blue;
|
style={{ border: "2px solid blue" }}
|
border-radius: 8px;
|
style={{ borderRadius: "8px" }}
|
text-align: center;
|
style={{ textAlign: "center" }}
|
lineHeight
) can be numbers.
{`function Demo(){
return Hello
}`}
function App() {
return (
<div className="container" style={{color:"blue", fontSize:"20px"}}>
<h1>Welcome to JSX</h1>
<img src="logo.png" alt="logo" />
</div>
);
}
A Component is a small, reusable piece of code that represents a part of the User Interface (UI).
Components make it easier to build and maintain large applications by breaking the UI into smaller parts.
function Welcome() {
return Hello, Students ЁЯСЛ
;
}
export default Welcome;
import Welcome from "./Welcome";
function App() {
return (
);
}
export default App;
import React, { Component } from "react";
class Welcome extends Component {
render() {
return Hello, Students ЁЯСЛ (Class Component)
;
}
}
export default Welcome;
my-react-app/
тФВ
тФЬтФА index.html
тФЬтФА main.jsx
тФЬтФА App.jsx
тФЬтФА Component/
тФВ тФЬтФА Volu.jsx
тФВ тФФтФА Pk.jsx
тФФтФА package.json
// main.jsx
// Entry point of React app
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
// Grab the root div from index.html
const rootElement = document.getElementById('root');
const root = createRoot(rootElement);
// Render the App component inside StrictMode
root.render(
<StrictMode>
<App />
</StrictMode>
);
// App.jsx
// Main component that combines other components
import Mr from './Component/Volu.jsx';
import Add from './Component/Pk.jsx';
function App() {
return (
<div>
<Add /> {/* Renders Add component */}
<Mr /> {/* Renders Mr (Wedding Invitation) component */}
</div>
);
}
export default App;
// Volu.jsx
// Wedding Invitation component
function Mr() {
return (
<div style={{
border: "2px solid #ccc",
padding: "20px",
width: "400px",
fontFamily: "Arial, sans-serif",
margin: "20px auto"
}}>
<h2 style={{ textAlign: "center", color: "#d6336c" }}>Wedding Invitation</h2>
<p style={{ textAlign: "center" }}>John Doe & Jane Smith</p>
<p style={{ textAlign: "center" }}>Date: October 10, 2025</p>
<p style={{ textAlign: "center" }}>Venue: Sunshine Banquet Hall, Patna</p>
<p style={{ textAlign: "center" }}>RSVP: 9430556829</p>
</div>
);
}
export default Mr;
// Pk.jsx
// Simple component for demonstration
function Add() {
return (
<div style={{
border: "2px solid #007bff",
padding: "10px",
width: "400px",
fontFamily: "Arial, sans-serif",
margin: "20px auto",
textAlign: "center",
color: "#007bff"
}}>
<h3>Hello, Students!</h3>
<p>This is an example React component.</p>
</div>
);
}
export default Add;
Props рдХрд╛ рдорддрд▓рдм рд╣реИ Propertiesред рдпрд╣ рдПрдХ рддрд░реАрдХрд╛ рд╣реИ рдЬрд┐рд╕рд╕реЗ рд╣рдо Parent Component рд╕реЗ Child Component рдХреЛ data рднреЗрдЬ рд╕рдХрддреЗ рд╣реИрдВред
// App.jsx
import Welcome from "./Welcome";
function App() {
return (
<div>
<Student name="Praveen" age="22" />
<Student name="Aman" age="21" />
</div>
);
}
// Welcome.jsx
function Student(props) {
return (
<h2>Hello, my name is {props.name} and I am {props.age} years old.</h2>
);
}
export default App;
Hello, my name is Praveen and I am 22 years old. Hello, my name is Aman and I am 21 years old.
рдЖрдк React рдореЗрдВ рдПрдХ рд╕реЗ рдЬреНрдпрд╛рджрд╛ properties (props) рдПрдХ component рдХреЛ pass рдХрд░ рд╕рдХрддреЗ рд╣реИрдВред
рд╣рд░ attribute automatically component рдореЗрдВ object рдХреА property рдмрди рдЬрд╛рддрд╛ рд╣реИред
props.propertyName
рд╕реЗред// Parent Component
function App() {
return (
<div>
<Car brand="Ford" model="Mustang" color="Red" year="2024" />
</div>
);
}
// Child Component
function Car(props) {
return (
<h2>
I have a {props.color} {props.brand} {props.model} from {props.year}.
</h2>
);
}
I have a Red Ford Mustang from 2024.
English: When we pass multiple props to a component, writing props.name
,
props.age
again and again becomes lengthy. To make it shorter and cleaner,
we use destructuring.
рд╣рд┐рдВрджреА: рдЬрдм рд╣рдо рдХрд┐рд╕реА component рдХреЛ multiple props pass рдХрд░рддреЗ рд╣реИрдВ, рддреЛ рдмрд╛рд░-рдмрд╛рд░
props.name
, props.age
рд▓рд┐рдЦрдирд╛ рд▓рдВрдмрд╛ рд╣реЛ рдЬрд╛рддрд╛ рд╣реИред
рдЗрд╕реЗ рдЖрд╕рд╛рди рдФрд░ readable рдмрдирд╛рдиреЗ рдХреЗ рд▓рд┐рдП рд╣рдо destructuring рдХрд╛ рдЗрд╕реНрддреЗрдорд╛рд▓ рдХрд░рддреЗ рд╣реИрдВред
// Parent Component
function App() {
return (
<div>
<Student name="Praveen" age="22" course="React" />
</div>
);
}
// Child Component
function Student(props) {
return (
<h2>
My name is {props.name}, I am {props.age} years old and learning {props.course}.
</h2>
);
}
// Parent Component
function App() {
return (
<div>
<Student name="Praveen" age="22" course="React" />
</div>
);
}
// Child Component (using destructuring)
function Student({ name, age, course }) {
return (
<h2>
My name is {name}, I am {age} years old and learning {course}.
</h2>
);
}
My name is Praveen, I am 22 years old and learning React.
English: In React, you can send the content between the opening and closing tags of a component to another component.
This can be accessed in the other component using the props.children
property.
рд╣рд┐рдВрджреА: React рдореЗрдВ, рдЖрдк рдХрд┐рд╕реА component рдХреЗ opening рдФрд░ closing tags рдХреЗ рдмреАрдЪ рдХрд╛ content рджреВрд╕рд░реЗ component рдореЗрдВ рднреЗрдЬ рд╕рдХрддреЗ рд╣реИрдВред
рдЗрд╕реЗ рджреВрд╕рд░реЗ component рдореЗрдВ props.children
рдХреА рдорджрдж рд╕реЗ access рдХрд┐рдпрд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИред
props.children
contains whatever content is placed between the component tags.props.children
рдореЗрдВ рд╡рд╣ content рд╣реЛрддрд╛ рд╣реИ рдЬреЛ component рдХреЗ tags рдХреЗ рдмреАрдЪ рд░рдЦрд╛ рдЧрдпрд╛ рд╣реЛред// Parent Component App.jsx
import Age from './Praveen.jsx';
import Date from './Pankaj.jsx';
import Card from './Card.jsx';
function App() {
return (
<>
<Age time="26 jan"/>
<Date />
<Card>
<h2>React рдореЗрдВ, рдЖрдк рдХрд┐рд╕реА component рдХреЗ opening рдФрд░ closing tags рдХреЗ рдмреАрдЪ рдХрд╛ content рджреВрд╕рд░реЗ
component рдореЗрдВ рднреЗрдЬ рд╕рдХрддреЗ рд╣реИрдВред рдЗрд╕реЗ рджреВрд╕рд░реЗ component рдореЗрдВ props.children
рдХреА рдорджрдж рд╕реЗ access рдХрд┐рдпрд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИред</h2>
</Card>
</>
)
}
export default App;
// Child Component Card,jsx
function Card(props) {
return (
<div style={{ border: "2px solid blue", padding: "10px", margin: "10px" }}>
{props.children} // Accessing children content
</div>
);
}
export default Card;
React рдореЗрдВ, рдЖрдк рдХрд┐рд╕реА component рдХреЗ opening рдФрд░ closing tags рдХреЗ рдмреАрдЪ рдХрд╛ content рджреВрд╕рд░реЗ component рдореЗрдВ рднреЗрдЬ рд╕рдХрддреЗ рд╣реИрдВред рдЗрд╕реЗ рджреВрд╕рд░реЗ component рдореЗрдВ props.children рдХреА рдорджрдж рд╕реЗ access рдХрд┐рдпрд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИред // Accessing children content
React рдореЗрдВ Events рдХрд╛ рдорддрд▓рдм рд╣реИ тАУ рдЬрдм user рдХреЛрдИ action рдХрд░рддрд╛ рд╣реИ (рдЬреИрд╕реЗ button click рдХрд░рдирд╛, input box рдореЗрдВ type рдХрд░рдирд╛, form submit рдХрд░рдирд╛)ред
React рдХреЗ events normal HTML events рдЬреИрд╕реЗ рд╣реА рд╣реЛрддреЗ рд╣реИрдВ, рд▓реЗрдХрд┐рди рдЙрдирдХрд╛ syntax рдЕрд▓рдЧ рд╣реЛрддрд╛ рд╣реИ:
HTML рдореЗрдВ тЖТ onclick="myFunction()" React рдореЗрдВ тЖТ onClick={myFunction} React events рд╣рдореЗрд╢рд╛ camelCase (рдЫреЛрдЯреЗ-рдмрдбрд╝реЗ рдЕрдХреНрд╖рд░реЛрдВ рдХреЗ format) рдореЗрдВ рд▓рд┐рдЦреЗ рдЬрд╛рддреЗ рд╣реИрдВред
тЬНя╕П English Notes (for writing)
Definition: Events are actions that occur when users interact with elements (e.g., click, type, submit).
React events are written in camelCase and functions are passed inside curly braces { }.
function ButtonExample() {
function handleClick() {
alert("Button clicked!");
}
return (
<button onClick={handleClick} className="btn">Click Me</button>
);
}
export default ButtonExample;
Output in App.jsx:
import ButtonExample from './event.jsx';
function App() {
return (
<div>
<h1>React Events Demo</h1>
<ButtonExample />
</div>
);
}
export default App;
Explanation: Separate function handleClick() рдХреЛ button рдореЗрдВ onClick рдХреЗ рдЬрд░рд┐рдП use рдХрд┐рдпрд╛ рдЧрдпрд╛ рд╣реИред
function InlineExample() {
return (
<button onClick={() => alert("Inline function triggered!")}>
Click Inline
</button>
);
}
export default InlineExample;
Explanation: Separate function рдХреЗ рдмрдЬрд╛рдп arrow function рд╕реАрдзреЗ onClick рдореЗрдВ рд▓рд┐рдЦрд╛ рдЧрдпрд╛ред рдЫреЛрдЯреЗ actions рдХреЗ рд▓рд┐рдП use рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред
рд╣рд┐рдВрджреА рдореЗрдВ рд╕рдордЭрдирд╛:State React рдХрд╛ рдПрдХ built-in feature рд╣реИ рдЬреЛ data рдХреЛ store рдХрд░рддрд╛ рд╣реИ рдФрд░ рдЬрдм data change рд╣реЛрддрд╛ рд╣реИ рддреЛ component automatically re-render рд╣реЛрддрд╛ рд╣реИред
English:: State is a built-in object in React used to store dynamic data. When the state changes, the component re-renders.
// Counter.jsx
import { useState } from "react";
function Counter(){
const [count, setCount] = useState(0); // initial state = 0
function increase(){
setCount(count + 1);
}
return(
<div>
<h1>counter {count}</h1>
<button onClick={increase}>increase</button>
</div>
)
}
export default Counter;
Explanation
count = current state value
setCount = function to update state
useState(0) = initial value of state is 0
рдиреАрдЪреЗ React `useState` рдХреЗ рдЙрджрд╛рд╣рд░рдг рдХрд╛ рдкреВрд░рд╛ step-by-step рд╡рд┐рд╡рд░рдг рд╣реИ тАФ рд╣рд░ рд▓рд╛рдЗрди рдХреЛ рдЖрд╕рд╛рди рд╣рд┐рдВрджреА рдореЗрдВ рд╕рдордЭрд╛рдпрд╛ рдЧрдпрд╛ рд╣реИред
import { useState } from "react";
рдпрд╣рд╛рдБ рд╣рдо React рдХрд╛ useState
hook рд▓рд╛рддреЗ рд╣реИрдВ, рдЬреЛ functional components рдореЗрдВ state рдмрдирд╛рдиреЗ рдХреЗ рдХрд╛рдо рдЖрддрд╛ рд╣реИред
function Counter() { ... }
рдпреЗ рдПрдХ React functional component рд╣реИред рдЬрдм рдЗрд╕реЗ render рд╣реЛрдирд╛ рд╣реЛрдЧрд╛ React рдпрд╣ function рдЪрд▓рд╛рдПрдЧрд╛ рдФрд░ JSX рд▓реМрдЯрд╛рдПрдЧрд╛ред
const [count, setCount] = useState(0);
`useState(0)` call рдХрд░рдиреЗ рдкрд░ React рдпрд╣ рдЬреЛрдбрд╝реА рджреЗрддрд╛ рд╣реИ: [stateValue, setterFunction]
ред
рдпрд╣рд╛рдБ count
= current state value (рдкрд╣рд▓реА рдмрд╛рд░ рдпрд╣ 0 рд╣реЛрдЧрд╛)ред
setCount
= рд╡рд╣ function рдЬрд┐рд╕рд╕реЗ рд╣рдо state рдмрджрд▓реЗрдВрдЧреЗред
рдзреНрдпрд╛рди: 0
рдХреЗрд╡рд▓ рдкрд╣рд▓реА рд░реЗрдВрдбрд░ рдкрд░ initial value рдХреЗ рд░реВрдк рдореЗрдВ use рд╣реЛрддреА рд╣реИ тАФ рдЖрдЧреЗ React internal рдореЗрдВ state рдХреЛ рд░рдЦрддрд╛ рд╣реИред
function increase() { setCount(count + 1); }
рдпрд╣ event handler рд╣реИред рдЬрдм рд╣рдо button рдкрд░ рдХреНрд▓рд┐рдХ рдХрд░реЗрдВрдЧреЗ, рдпреЗ function рдЪрд▓рдХрд░ setCount
рдХреЛ рдмреБрд▓рд╛рдПрдЧрд╛ред
setCount(count + 1)
рдХрд╛ рдорддрд▓рдм рд╣реИ: рдирдП state рдХреЗ рд▓рд┐рдП current count
рдореЗрдВ 1 рдЬреЛрдбрд╝ рджреЛ рдФрд░ React рдХреЛ рдмрддрд╛рдУ state рдмрджрд▓ рдЧрдИ рд╣реИред
рдиреАрдЪреЗ рд╡рд╛рд▓реЗ JSX рдореЗрдВ:
<h2>Count: {count}</h2>
<button onClick={increase}>Increase</button>
<h2>
рдореЗрдВ {count}
current state рджрд┐рдЦрд╛рддрд╛ рд╣реИред
onClick={increase}
тАФ рдпрд╣рд╛рдБ рд╣рдо function рдХрд╛ reference рджреЗ рд░рд╣реЗ рд╣реИрдВ (рдЗрд╕реЗ рдХреЙрд▓ рдирд╣реАрдВ рдХрд░ рд░рд╣реЗ)ред рдмреНрд░рд╛рдЙрдЬрд╝рд░ click рд╣реЛрдиреЗ рдкрд░ React рдпрд╣ function рдЪрд▓рд╛рдПрдЧрд╛ред
React Counter()
call рдХрд░рддрд╛ рд╣реИ тЖТ useState(0)
рджреЗрддрд╛ рд╣реИ тЖТ component JSX рд▓реМрдЯрддрд╛ рд╣реИ тЖТ Browser рдореЗрдВ DOM mount рд╣реЛрддрд╛ рд╣реИ тЖТ рдЖрдк рджреЗрдЦрддреЗ рд╣реИрдВ: Count: 0 рдФрд░ рдПрдХ Increase buttonред
Browser event тЖТ React runs increase()
тЖТ setCount(count + 1)
execute рд╣реЛрддрд╛ рд╣реИред
setCount
React рдХреЛ рдмрддрд╛рддрд╛ рд╣реИ рдХрд┐ state рдмрджрд▓ рдЧрдИ (рдЕрдм new count
= old count
+ 1)ред
React component рдХреЛ рдлрд┐рд░ рд╕реЗ re-render рдХрд░рддрд╛ рд╣реИ: Counter()
рдлрд┐рд░ рд╕реЗ рдЪрд▓рддреА рд╣реИ рд▓реЗрдХрд┐рди рдЕрдм useState
рд╕реЗ count
рдХреА value рдирдИ (updated) рд╣реЛрддреА рд╣реИред
JSX рдлрд┐рд░ рд╕реЗ рдмрдирддрд╛ рд╣реИ рдФрд░ DOM рдореЗрдВ рдЬреЛ рдмрджрд▓рд╛ рд╣реИ рд╡реЛ update рдХрд░ рджрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ (virtual DOM diffing рдХреЗ рдмрд╛рдж actual DOM update рд╣реЛрддрд╛ рд╣реИ)ред
UI рдЕрдм рджрд┐рдЦрд╛рдПрдЧрд╛: Count: 1 (рдкрд╣рд▓реА рдХреНрд▓рд┐рдХ рдХреЗ рдмрд╛рдж)ред
рд╣рд░ click рдкрд░ рдКрдкрд░ рд╡рд╛рд▓рд╛ process рджреБрд╣рд░рд╛рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ: count
рдмрдврд╝рддреА рдЬрд╛рддреА рд╣реИ тЖТ re-render тЖТ UI updateред
Step | count value |
Screen рдкрд░ рдХреНрдпрд╛ рджрд┐рдЦреЗрдЧрд╛ |
---|---|---|
Initial render | 0 | Count: 0 |
After 1st click | 1 | Count: 1 |
After 2nd click | 2 | Count: 2 |
Advanced note: рдЕрдЧрд░ рдЖрдк рдПрдХ рд╣реА handler рдореЗрдВ рдХрдИ рдмрд╛рд░ state рдкрд░ рдирд┐рд░реНрднрд░ updates рдХрд░ рд░рд╣реЗ рд╣реЛрдВ рддреЛ functional update pattern (e.g., setCount(prev => prev + 1)
) рдЗрд╕реНрддреЗрдорд╛рд▓ рдХрд░реЗрдВ рддрд╛рдХрд┐ stale value рдХреА problem рди рдЖрдПред
// Multiplestate.jsx
import { useState } from "react";
function UserInfo() {
const [name, setName] = useState("Praveen");
const [age, setAge] = useState(22);
return (
<div>
<h>Name: {name}</h>
<h>Age: {age}</h>
<button onClick={() => setAge(age + 1)}<Increase Age</button>
</div>
)
}
export default UserInfo;
рд╣рд┐рдВрджреА рдореЗрдВ рд╕рдордЭрдирд╛: React рдореЗрдВ Conditional Rendering рдХрд╛ рдорддрд▓рдм рд╣реИ рдХрд┐ рдХрд┐рд╕реА condition рдХреЗ рдЖрдзрд╛рд░ рдкрд░ component рдХрд╛ рдХреБрдЫ рд╣рд┐рд╕реНрд╕рд╛ рджрд┐рдЦрд╛рдирд╛ рдпрд╛ рдирд╣реАрдВ рджрд┐рдЦрд╛рдирд╛ред
English Notes: Conditional Rendering in React means rendering components or elements based on certain conditions.
// PAGE NAME : Ifcondition.jsx
function Greeting(props) {
const isLoggedIn = props.isLoggedIn;
if (isLoggedIn) {
return <h2>Welcome back!</h2>;
} else {
return <h2>Please log in.</h2>;
}
}
export default Greeting;
// PAGE NAME : App.jsx
import Ifcondition from './Ifcondition.jsx';
function App() {
return (
<ButtonExample />
<Ifcondition isLoggedIn ={true} />
)
}
export default App
Explanation:
isLoggedIn = true
тЖТ "Welcome back!" рджрд┐рдЦреЗрдЧрд╛редisLoggedIn = false
тЖТ "Please log in." рджрд┐рдЦреЗрдЧрд╛ред
function Greeting(props) {
return (
<div>
{props.isLoggedIn ? <h2>Welcome back!</h2> : <h2>Please log in.</h2>}
</div>
);
}
export default Greeting;
Explanation:
condition ? trueJSX : falseJSX
.
function Message(props) {
const isLoggedIn = props.isLoggedIn;
return (
<div>
{isLoggedIn && <h2>Welcome back!</h2>}
</div>
);
}
export default Message;
Explanation:
isLoggedIn = true
тЖТ JSX render рд╣реЛрдЧрд╛редisLoggedIn = false
тЖТ рдХреБрдЫ рдирд╣реАрдВ рджрд┐рдЦреЗрдЧрд╛редрд╣рд┐рдВрджреА рдореЗрдВ рд╕рдордЭрдирд╛: React рдореЗрдВ рдЕрдЧрд░ рд╣рдореЗрдВ рдПрдХ рд╣реА type рдХреЗ data рдХреЛ рдмрд╛рд░-рдмрд╛рд░ render рдХрд░рдирд╛ рд╣реИ (рдЬреИрд╕реЗ names, products, todos), рддреЛ рд╣рдо map()
function рдХрд╛ рдЗрд╕реНрддреЗрдорд╛рд▓ рдХрд░рддреЗ рд╣реИрдВред
English Notes: Lists in React are used to render multiple items dynamically. We usually use JavaScript map()
method to transform an array into JSX elements.
function NameList() {
const names = ["Praveen", "Pankaj", "Neha"];
return (
<ul>
{names.map((name) => (
<li>{name}</li>
))}
</ul>
);
}
export default NameList;
Explanation:
names
рдХреЗ рд╣рд░ item рдХреЛ map() function рд╕реЗ list item (<li>) рдореЗрдВ рдмрджрд▓рд╛редmap()
.Hindi: Forms React рдореЗрдВ user input рд▓реЗрдиреЗ рдХрд╛ рддрд░реАрдХрд╛ рд╣реИрдВред рдЬреИрд╕реЗ HTML рдореЗрдВ <input>
, <textarea>
, <select>
рдЖрджрд┐ред
English: Forms allow users to enter data, just like in HTML, but in React we usually use state to manage input values.
Hindi: рдЬрдм input рдХрд╛ value React state рдХреЗ рджреНрд╡рд╛рд░рд╛ control рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ рддреЛ рдЙрд╕реЗ controlled component рдХрд╣рддреЗ рд╣реИрдВред
English: A controlled component is a form element whose value is controlled by React state.
import { useState } from "react";
function NameForm() {
const [name, setName] = useState("");
function handleChange(event) {
setName(event.target.value);
}
function handleSubmit(event) {
event.preventDefault();
alert("Submitted Name: " + name);
}
return (
<form onSubmit={handleSubmit}>
<label>
Name:
<input type="text" value={name} onChange={handleChange} />
</label>
<button type="submit">Submit</button>
</form>
);
}
export default NameForm;
const [name, setName] = useState("");
- input value store рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдПредimport { useState } from "react";
function MultipleForm() {
const [formData, setFormData] = useState({ firstName: "", lastName: "" });
function handleChange(event) {
const { name, value } = event.target;
setFormData({ ...formData, [name]: value });
}
function handleSubmit(event) {
event.preventDefault();
alert(`Hello ${formData.firstName} ${formData.lastName}`);
}
return (
<form onSubmit={handleSubmit}>
<input name="firstName" value={formData.firstName} onChange={handleChange} placeholder="First Name" />
<input name="lastName" value={formData.lastName} onChange={handleChange} placeholder="Last Name" />
<button type="submit">Submit</button>
</form>
);
}
export default MultipleForm;
import { useState } from "react";
function SelectForm() {
const [fruit, setFruit] = useState("apple");
function handleChange(event) {
setFruit(event.target.value);
}
function handleSubmit(event) {
event.preventDefault();
alert("Selected Fruit: " + fruit);
}
return (
<form onSubmit={handleSubmit}>
<select value={fruit} onChange={handleChange}>
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="mango">Mango</option>
</select>
<button type="submit">Submit</button>
</form>
);
}
export default SelectForm;
value
attribute + onChange
handler рдЬрд░реВрд░реАредevent.preventDefault()
form submit рдореЗрдВ page reload рд░реЛрдХрддрд╛ рд╣реИред[name]: value
Feature | Hindi | English |
---|---|---|
Controlled Component | Input value state рд╕реЗ control | Value controlled by React state |
onChange | Typing handle рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП | Handle typing events |
onSubmit | Form submit handle, reload рд░реЛрдХрдирд╛ | Handle form submit, prevent page reload |
Multiple Fields | object state + [name]: value | object state + dynamic update |
Select / Dropdown | same concept as input | same concept |
рд╣рд┐рдВрджреА рдореЗрдВ рд╕рдордЭрдирд╛: Checkbox form element рд╣реЛрддрд╛ рд╣реИ рдЬреЛ user рдХреЛ "рд╣рд╛рдБ / рдирд╣реАрдВ" (true/false) рдпрд╛ multiple options select рдХрд░рдиреЗ рджреЗрддрд╛ рд╣реИред
English Notes: Checkbox is a form element that allows users to select or deselect options тАФ useful for boolean or multi-select input.
import { useState } from "react";
function CheckboxExample() {
const [isChecked, setIsChecked] = useState(false);
function handleChange(event) {
setIsChecked(event.target.checked); // тЬЕ checkbox 'checked' рд╕реЗ value рдЖрддреА рд╣реИ
}
function handleSubmit(event) {
event.preventDefault();
alert("Checkbox is " + (isChecked ? "Checked тЬЕ" : "Not Checked тЭМ"));
}
return (
<form onSubmit={handleSubmit}>
<label>
<input type="checkbox" checked={isChecked} onChange={handleChange} />
I agree to the Terms & Conditions
</label>
<br />
<button type="submit">Submit</button>
</form>
);
}
export default CheckboxExample;
Step-by-Step Explanation:
import { useState } from "react";
function MultipleCheckbox() {
const [hobbies, setHobbies] = useState({
cricket: false,
music: false,
reading: false
});
function handleChange(event) {
const { name, checked } = event.target;
setHobbies({ ...hobbies, [name]: checked });
}
function handleSubmit(event) {
event.preventDefault();
const selected = Object.keys(hobbies).filter(hobby => hobbies[hobby]);
alert("Selected hobbies: " + (selected.length ? selected.join(", ") : "None"));
}
return (
<form onSubmit={handleSubmit}>
<label>
<input type="checkbox" name="cricket" checked={hobbies.cricket} onChange={handleChange} /> Cricket
</label><br/>
<label>
<input type="checkbox" name="music" checked={hobbies.music} onChange={handleChange} /> Music
</label><br/>
<label>
<input type="checkbox" name="reading" checked={hobbies.reading} onChange={handleChange} /> Reading
</label><br/>
<button type="submit">Submit</button>
</form>
);
}
export default MultipleCheckbox;
Step-by-Step Explanation:
Concept | Hindi Explanation | English Explanation |
---|---|---|
checked | Checkbox рдХреА current рд╕реНрдерд┐рддрд┐ (true/false) | Reflects checkbox current state |
onChange | рд╣рд░ click рдкрд░ value update рдХрд░рддрд╛ рд╣реИ | Updates state on user click |
Multiple Checkbox | object state рдореЗрдВ handle рдХрд░рдирд╛ рдЖрд╕рд╛рди | Manage using object with keys |
Controlled Component | state рд╕реЗ checkbox control | Checkbox controlled by React state |
рд╣рд┐рдВрджреА рдореЗрдВ рд╕рдордЭрдирд╛: Radio buttons рдПрдХ form element рд╣реЛрддреЗ рд╣реИрдВ рдЬреЛ user рдХреЛ рдПрдХ group рдореЗрдВ рд╕реЗ рдХреЗрд╡рд▓ рдПрдХ option рдЪреБрдирдиреЗ рдХреА рдЕрдиреБрдорддрд┐ рджреЗрддреЗ рд╣реИрдВред
English Notes: Radio buttons allow users to select only one option from a predefined group.
import { useState } from "react";
function RadioExample() {
const [gender, setGender] = useState("");
function handleChange(event) {
setGender(event.target.value);
}
function handleSubmit(event) {
event.preventDefault();
alert("Selected Gender: " + (gender || "None"));
}
return (
<form onSubmit={handleSubmit}>
<h3>Select Gender:</h3>
<label>
<input
type="radio"
name="gender"
value="Male"
checked={gender === "Male"}
onChange={handleChange}
/>
Male
</label>
<br />
<label>
<input
type="radio"
name="gender"
value="Female"
checked={gender === "Female"}
onChange={handleChange}
/>
Female
</label>
<br />
<label>
<input
type="radio"
name="gender"
value="Other"
checked={gender === "Other"}
onChange={handleChange}
/>
Other
</label>
<br /><br />
<button type="submit">Submit</button>
</form>
);
}
export default RadioExample;
Step-by-Step Explanation:
Concept | Hindi Explanation | English Explanation |
---|---|---|
Radio Buttons | рдПрдХ group рдореЗрдВ рд╕реЗ рд╕рд┐рд░реНрдл рдПрдХ option рдЪреБрдирдиреЗ рдХреЗ рд▓рд┐рдП | Used for single selection within a group |
name Attribute | рд╕рднреА radio buttons рдореЗрдВ рдПрдХ рдЬреИрд╕рд╛ name рд╣реЛрдирд╛ рдЪрд╛рд╣рд┐рдП | All radios in a group must share same name |
checked | рдЬреЛ option рдЪреБрдирд╛ рдЧрдпрд╛ рд╣реИ рд╡рд╣реА checked=true рд╣реЛрддрд╛ рд╣реИ | Determines which radio is selected |
onChange | рдЬрдм user select рдХрд░рддрд╛ рд╣реИ рддреЛ value update рд╣реЛрддреА рд╣реИ | Triggered when selection changes |
рд╣рд┐рдВрджреА рдореЗрдВ рд╕рдордЭрдирд╛: React Portals рдХрд╛ рдЗрд╕реНрддреЗрдорд╛рд▓ рддрдм рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ рдЬрдм рд╣рдореЗрдВ рдХрд┐рд╕реА component рдХреЛ рдЙрд╕рдХреЗ parent component рдХреЗ рдмрд╛рд╣рд░ DOM tree рдореЗрдВ render рдХрд░рдирд╛ рд╣реЛред
English Notes: React Portals allow you to render a child component into a different part of the DOM, outside of its parent hierarchy.
import ReactDOM from "react-dom";
function Modal({ children }) {
// Modal рдХреЛ id="modal-root" рд╡рд╛рд▓реЗ div рдореЗрдВ render рдХрд░реЗрдВрдЧреЗ
return ReactDOM.createPortal(
<div style={{
position: "fixed",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
background: "white",
padding: "20px",
border: "2px solid black",
boxShadow: "0 0 10px rgba(0,0,0,0.3)"
}}>
{children}
</div>,
document.getElementById("modal-root")
);
}
export default Modal;
import { useState } from "react";
import Modal from "./Modal.jsx";
function App() {
const [isOpen, setIsOpen] = useState(false);
return (
<>
<h1>React Portal Example</h1>
<button onClick={() => setIsOpen(true)}>Open Modal</button>
{isOpen && (
<Modal>
<h2>Hello from the Portal! ЁЯСЛ</h2>
<button onClick={() => setIsOpen(false)}>Close</button>
</Modal>
)}
</>
);
}
export default App;
Portals рдХреЛ рдХрд╛рдо рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП, index.html рдореЗрдВ рдПрдХ extra div рдЪрд╛рд╣рд┐рдП:
<div id="root"></div>
<div id="modal-root"></div> <!-- Modal рдпрд╣реА render рд╣реЛрдЧрд╛ -->
Concept | Hindi Explanation | English Explanation |
---|---|---|
ReactDOM.createPortal | Component рдХреЛ рдХрд┐рд╕реА рдФрд░ DOM node рдореЗрдВ render рдХрд░рддрд╛ рд╣реИ | Renders children into a different DOM node |
Use Case | Modals, Popups, Tooltips рдЖрджрд┐ | Useful for modals, tooltips, and overlays |
DOM Separation | Parent hierarchy рддреЛрдбрд╝реЗ рдмрд┐рдирд╛ UI рдЕрд▓рдЧ рдЬрдЧрд╣ render рдХрд░рддрд╛ рд╣реИ | DoesnтАЩt break React component hierarchy |
рд╣рд┐рдВрджреА рдореЗрдВ: Suspense рдПрдХ React feature рд╣реИ рдЬреЛ lazy loading components рдпрд╛ asynchronous data рдХреЗ рд▓рд┐рдП рдЗрд╕реНрддреЗрдорд╛рд▓ рд╣реЛрддрд╛ рд╣реИред рдпрд╣ UI рдХреЛ temporarily "рд░реЛрдХрддрд╛" рд╣реИ рдЬрдм рддрдХ component load рди рд╣реЛ рдЬрд╛рдП, рдФрд░ loading fallback рджрд┐рдЦрд╛рддрд╛ рд╣реИред
English Notes: Suspense is a React feature for handling lazy-loaded components or asynchronous data. It allows showing a fallback UI while waiting for content to load.
import { Suspense, lazy } from 'react';
const LazyComponent = lazy(() => import('./Suspence.jsx'));
function App() {
return (
<div>
<Suspense fallback={<div>Loading...</div>}>
<LazyComponent />
</Suspense>
</div>
);
}
export default App;
function LazyComponent() {
return <h2>Hello! I am loaded lazily. ЁЯОЙ</h2>;
}
export default LazyComponent;
Concept | Hindi Explanation | English Explanation |
---|---|---|
React.lazy | Component рдХреЛ lazy load рдХрд░рддрд╛ рд╣реИ | Dynamically imports component only when needed |
Suspense | Lazy component рдХреЗ рдЪрд╛рд░реЛрдВ рдУрд░ wrap | Wraps lazy component and shows fallback UI |
fallback | Loading state рдореЗрдВ UI рджрд┐рдЦрд╛рддрд╛ рд╣реИ | UI displayed while waiting for component |
Use Case | Large app, API fetch, split bundles | Optimizing large apps or asynchronous data |
рд╣рд┐рдВрджреА рдореЗрдВ: React components рдореЗрдВ рд╣рдо CSS рдХрд╛ рдЗрд╕реНрддреЗрдорд╛рд▓ рдХрд░рдХреЗ UI рдХреЛ style рдХрд░ рд╕рдХрддреЗ рд╣реИрдВред рдЗрд╕рдХреЗ рдореБрдЦреНрдп рддреАрди рддрд░реАрдХреЗ рд╣реИрдВ: Inline Styling, CSS Stylesheets, рдФрд░ CSS Modulesред
English Notes: In React, you can style components using CSS. There are mainly three ways: Inline Styling, CSS Stylesheets, and CSS Modules.
Hindi: Inline style attribute рдореЗрдВ styling рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП value рд╣рдореЗрд╢рд╛ JavaScript object рд╣реЛрддреА рд╣реИред
English: Inline styles require a JavaScript object as the value.
const Header = () => {
return (
<>
<h1 style={{color: "red"}}>Hello Style!</h1>
<p>Add a little style!</p>
</>
);
}
Note: JSX рдореЗрдВ JavaScript expressions curly braces {} рдореЗрдВ рд▓рд┐рдЦрддреЗ рд╣реИрдВред рдЪреВрдБрдХрд┐ style рдХреЗ рд▓рд┐рдП object рднреА curly braces use рдХрд░рддрд╛ рд╣реИ, рдЗрд╕рд▓рд┐рдП double curly braces {{}} рд╣реЛрддреЗ рд╣реИрдВред
const Header = () => {
return (
<>
<h1 style={{backgroundColor: "lightblue"}}>Hello Style!</h1>
<p>Add a little style!</p>
</>
);
}
const Header = () => {
const myStyle = {
color: "white",
backgroundColor: "DodgerBlue",
padding: "10px",
fontFamily: "Sans-Serif"
};
return (
<>
<h1 style={myStyle}>Hello Style!</h1>
<p>Add a little style!</p>
</>
);
}
Hindi: CSS рдХреЛ рдЕрд▓рдЧ .css file рдореЗрдВ рд▓рд┐рдЦреЗрдВ рдФрд░ component рдореЗрдВ import рдХрд░реЗрдВред
English: Write CSS in a separate .css file and import it in your component.
/* MyStylesheet.css */
body {
background-color: #282c34;
color: white;
padding: 40px;
font-family: Sans-Serif;
text-align: center;
}
/* index.js */
import { createRoot } from 'react-dom/client';
import './MyStylesheet.css';
const Header = () => {
return (
<>
<h1>Hello Style!</h1>
<p>Add a little style!</p>
</>
);
}
createRoot(document.getElementById('root')).render(
<Header />
);
Hindi: Components рдХреЗ рд▓рд┐рдП local scope stylingред Name conflicts рд╕реЗ рдмрдЪрд╛рддрд╛ рд╣реИред
English: Provides local scoped styling for components, preventing name conflicts.
/* my-style.module.css */
.bigred {
color: Tomato;
padding: 40px;
font-family: Sans-Serif;
text-align: center;
}
/* index.jsx */
import { createRoot } from 'react-dom/client';
import styles from './my-style.module.css';
const Car = () => {
return <h1 className={styles.bigred}>Hello Car!</h1>;
}
createRoot(document.getElementById('root')).render(
<Car />
);
Method | Hindi Explanation | English Explanation |
---|---|---|
Inline CSS | Element рдХреЗ style attribute рдореЗрдВ JS object use | Apply styling using JS object directly on element |
CSS Stylesheet | Separate .css file import рдХрд░рдХреЗ styling | Import separate .css file for styling |
CSS Modules | Local scope styling with module import | Scoped styling by importing CSS module |
рд╣рд┐рдВрджреА рдореЗрдВ: CSS Modules React рдореЗрдВ components рдХреЗ рд▓рд┐рдП local scoped styling рджреЗрддреЗ рд╣реИрдВред рдЗрд╕рдХрд╛ рдорддрд▓рдм рд╣реИ рдХрд┐ imported CSS рдХреЗрд╡рд▓ рдЙрд╕реА component рдкрд░ apply рд╣реЛрдЧрд╛ рдФрд░ name conflicts рдирд╣реАрдВ рд╣реЛрдВрдЧреЗред
English Notes: CSS Modules provide local scoped styling for React components. Imported styles are only applied to that component, preventing class name conflicts.
CSS Module file рдХрд╛ рдирд╛рдо рд╣рдореЗрд╢рд╛ *.module.css
рд╣реЛрдирд╛ рдЪрд╛рд╣рд┐рдПред
/* my-style.module.css */
.bigred {
color: Tomato;
padding: 40px;
font-family: Sans-Serif;
text-align: center;
}
import styles from './my-style.module.css';
const Car = () => {
return <h1 className={styles.bigred}>Hello Car!</h1>;
}
export default Car;
Feature | Hindi Explanation | English Explanation |
---|---|---|
Local Scope | CSS рдХреЗрд╡рд▓ рдЙрд╕ component рддрдХ рд╕реАрдорд┐рдд рд░рд╣рддреА рд╣реИ | CSS is scoped to the importing component only |
No Name Conflicts | Class names clash рдирд╣реАрдВ рдХрд░реЗрдВрдЧреЗ | Prevents class name collisions in large apps |
Easy Maintenance | рд╣рд░ component рдХрд╛ styling рдЕрд▓рдЧ рд░рд╣рддрд╛ рд╣реИ | Each componentтАЩs styling is separate and maintainable |
*.module.css
file with your styles.import styles from './file.module.css'
.className={styles.className}
.рд╣рд┐рдВрджреА рдореЗрдВ: CSS-in-JS рдПрдХ approach рд╣реИ рдЬрд┐рд╕рдореЗрдВ CSS styles рд╕реАрдзреЗ JavaScript рдХреЗ рдЕрдВрджрд░ рд▓рд┐рдЦреЗ рдЬрд╛рддреЗ рд╣реИрдВред React рдореЗрдВ рдпрд╣ рдмрд╣реБрдд popular рд╣реИ рдХреНрдпреЛрдВрдХрд┐ рдпрд╣ component-based styling рдХреЛ рдЖрд╕рд╛рди рдмрдирд╛рддрд╛ рд╣реИред
English Notes: CSS-in-JS is an approach where CSS styles are written directly inside JavaScript. It is popular in React for easier component-based styling.
const Header = () => {
const style = {
color: "white",
backgroundColor: "DodgerBlue",
padding: "10px",
borderRadius: "5px",
textAlign: "center"
};
return <h1 style={style}>Hello CSS-in-JS!</h1>;
}
import styled from 'styled-components';
const Button = styled.button`
background-color: #b61561;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
&:hover {
background-color: #ff8a00;
}
`;
const App = () => {
return <Button>Click Me</Button>;
}
export default App;
Feature | Hindi Explanation | English Explanation |
---|---|---|
Scoped Styling | рд╣рд░ component рдХреА styling рдЕрд▓рдЧ рд░рд╣рддреА рд╣реИ | Each component has its own scoped styling |
Dynamically Change Styles | Props рдФрд░ state рдХреЗ рдЖрдзрд╛рд░ рдкрд░ styling рдмрджрд▓ рд╕рдХрддреЗ рд╣реИрдВ | Styles can change dynamically based on props and state |
No CSS File Needed | Extra CSS files maintain рдХрд░рдиреЗ рдХреА рдЬрд░реВрд░рдд рдирд╣реАрдВ | No need to maintain separate CSS files |
рд╣рд┐рдВрджреА рдореЗрдВ: React Router рдПрдХ library рд╣реИ рдЬреЛ React applications рдореЗрдВ multiple pages рдФрд░ navigation рдХреЗ рд▓рд┐рдП рдЗрд╕реНрддреЗрдорд╛рд▓ рд╣реЛрддреА рд╣реИред
English Notes: React Router is a library used to handle navigation and multiple pages in React applications.
npm install react-router-dom
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom';
function Home() { return <h1>Home Page</h1>; }
function About() { return <h1>About Page</h1>; }
function Contact() { return <h1>Contact Page</h1>; }
function App() {
return (
<BrowserRouter>
<nav>
<Link to="/">Home</Link> |{" "}
<Link to="/about">About</Link> |{" "}
<Link to="/contact">Contact</Link>
</nav>
<Routes>
<Route path="/" element=<Home /> />
<Route path="/about" element=<About /> />
<Route path="/contact" element=<Contact /> />
</Routes>
</BrowserRouter>
);
}
export default App;
рдЖрдк Route рдХреЗ рдЕрдВрджрд░ child Route define рдХрд░ рд╕рдХрддреЗ рд╣реИрдВред рдЗрд╕рд╕реЗ pages рдХреЗ рдЕрдВрджрд░ sub-pages manage рдХрд░рдирд╛ рдЖрд╕рд╛рди рд╣реЛрддрд╛ рд╣реИред
import { BrowserRouter, Routes, Route, Link, Outlet } from 'react-router-dom';
function Products() {
return (
<div>
<h1>Products</h1>
<nav>
<Link to="car">Cars</Link> |{" "}
<Link to="bike">Bikes</Link>
</nav>
<Outlet />
</div>
);
}
function CarProducts() { return <h2>Cars</h2>; }
function BikeProducts() { return <h2>Bikes</h2>; }
function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/products" element=<Products />>
<Route path="car" element=<CarProducts /> />
<Route path="bike" element=<BikeProducts /> />
</Route>
</Routes>
</BrowserRouter>
);
}
NavLink component active state detect рдХрд░рддрд╛ рд╣реИ рдФрд░ style рдмрджрд▓ рд╕рдХрддрд╛ рд╣реИред
import { NavLink } from 'react-router-dom';
const navLinkStyles = ({ isActive }) => ({
color: isActive ? '#007bff' : '#333',
fontWeight: isActive ? 'bold' : 'normal'
});
<NavLink to="/about" style={navLinkStyles}>About</NavLink>
Dynamic routes рдХреЗ рд▓рд┐рдП URL parameters use рдХрд┐рдП рдЬрд╛рддреЗ рд╣реИрдВ рддрд╛рдХрд┐ different values pass рдХреА рдЬрд╛ рд╕рдХреЗрдВред
import { useParams } from 'react-router-dom';
function Info() {
const { firstname } = useParams();
return <h1>Hello, {firstname}!</h1>;
}
<Route path="/customer/:firstname" element=<Info /> />
/customer/Emil
тЖТ Hello, Emil/customer/Tobias
тЖТ Hello, Tobiasрд╣рд┐рдВрджреА рдореЗрдВ: Hooks рдРрд╕реЗ functions рд╣реИрдВ рдЬреЛ React functional components рдореЗрдВ state рдФрд░ lifecycle features рдХреЛ enable рдХрд░рддреЗ рд╣реИрдВред
English Notes: Hooks are special functions that allow you to use state and other React features in functional components.
useState component рдХреЗ рдЕрдВрджрд░ data (state) store рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП use рд╣реЛрддрд╛ рд╣реИред
import { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<h2>Count: {count}</h2>
<button onClick={() => setCount(count + 1)}>Increase</button>
<button onClick={() => setCount(count - 1)}>Decrease</button>
</div>
);
}
export default Counter;
useEffect side-effects (рдЬреИрд╕реЗ API calls, timers, DOM updates) handle рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП use рд╣реЛрддрд╛ рд╣реИред
import { useState, useEffect } from 'react';
function Example() {
const [count, setCount] = useState(0);
useEffect(() => {
document.title = `You clicked ${count} times`;
}, [count]); // dependency array
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Click Me</button>
</div>
);
}
[count]
рджреА рд╣реИ тЖТ рд╕рд┐рд░реНрдл count change рд╣реЛрдиреЗ рдкрд░ рдЪрд▓реЗрдЧрд╛редGlobal data share рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП useContext hook use рд╣реЛрддрд╛ рд╣реИред
import { createContext, useContext } from 'react';
const UserContext = createContext();
function User() {
const user = useContext(UserContext);
return <h1>Hello, {user}!</h1>;
}
function App() {
return (
<UserContext.Provider value="Praveen">
<User />
</UserContext.Provider>
);
}
DOM elements рдХреЛ directly access рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП use рд╣реЛрддрд╛ рд╣реИред
import { useRef } from 'react';
function InputFocus() {
const inputRef = useRef(null);
const focusInput = () => {
inputRef.current.focus();
};
return (
<div>
<input ref={inputRef} placeholder="Type here..." />
<button onClick={focusInput}>Focus Input</button>
</div>
);
}
Expensive calculations рдХреЛ optimize рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП useMemo use рд╣реЛрддрд╛ рд╣реИред
import { useMemo, useState } from 'react';
function Calculate() {
const [num, setNum] = useState(0);
const expensiveCalc = useMemo(() => {
console.log("Calculating...");
return num * 10;
}, [num]);
return (
<div>
<input type="number" onChange={(e) => setNum(Number(e.target.value))} />
<h2>Result: {expensiveCalc}</h2>
</div>
);
}
useCallback functions рдХреЛ memoize рдХрд░рддрд╛ рд╣реИ рддрд╛рдХрд┐ unnecessary re-render рди рд╣реЛред
import { useState, useCallback } from 'react';
function Example() {
const [count, setCount] = useState(0);
const handleClick = useCallback(() => {
setCount(c => c + 1);
}, []);
return (
<div>
<p>Count: {count}</p>
<button onClick={handleClick}>Increase</button>
</div>
);
}