ЁЯУШ React JS рдХреНрдпрд╛ рд╣реИ?

ЁЯФ╣ ReactJS рдПрдХ JavaScript рд▓рд╛рдЗрдмреНрд░реЗрд░реА рд╣реИ рдЬреЛ рдпреВрдЬрд╝рд░ рдЗрдВрдЯрд░рдлреЗрд╕ (User Interface) рдпрд╛ UI рдмрдирд╛рдиреЗ рдХреЗ рд▓рд┐рдП рдкреНрд░рдпреЛрдЧ рд╣реЛрддреА рд╣реИред

тЬЕ React рд╕рд┐рд░реНрдл UI рдмрдирд╛рддрд╛ рд╣реИ, рдпрд╛рдиреА рдпрд╣ рдЖрдкрдХреА рд╡реЗрдмрд╕рд╛рдЗрдЯ рдпрд╛ рд╡реЗрдм рдРрдк рдХрд╛ "View" Layer рд╕рдВрднрд╛рд▓рддрд╛ рд╣реИред

ReactJS - Simplified Definition

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:

  • Functional Components
  • Class Components

React works using some important technologies and concepts:

  • DOM (Document Object Model): Structure of the web page
  • Virtual DOM: Improves performance by updating only changed parts
  • JSX (JavaScript XML): Lets you write HTML-like code inside JavaScript
  • Lifecycle Methods: Special functions used in class components such as:
    • render()
    • componentDidMount()
    • shouldComponentUpdate()
    • componentWillUnmount()
These features make React a powerful tool for building fast, dynamic, and reusable user interfaces.

ЁЯза React рдХреЛ рдХрд┐рд╕рдиреЗ рдмрдирд╛рдпрд╛?

ЁЯУЬ React рдХреА History

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ред

ЁЯОп React JS рдХреЗ Key Features

ЁЯУМ 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 рд╣реИред

ЁЯЪА React JS рдХрд╛ рдЗрд╕реНрддреЗрдорд╛рд▓ рдХрд╣рд╛рдБ рд╣реЛрддрд╛ рд╣реИ?

ЁЯзк React JS рдХреЗ рдореБрдЦреНрдп Concepts

ЁЯФв React JS рдХреЗ Versions Overview

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

ЁЯУМ React 19 рдореЗрдВ рдирдпрд╛ рдХреНрдпрд╛ рд╣реИ?

ЁЯСитАНЁЯТ╗ рдХреНрдпреЛрдВ рд╕реАрдЦреЗрдВ React JS?

ЁЯУЪ Conclusion:

React рдПрдХ modern JavaScript library рд╣реИ рдЬреЛ рдЖрдкрдХреЛ dynamic, fast рдФрд░ scalable web applications рдмрдирд╛рдиреЗ рдореЗрдВ рдорджрдж рдХрд░рддрд╛ рд╣реИред

ЁЯУШ Library vs Framework Explained (Hindi)

Library рдХреНрдпрд╛ рд╣реЛрддреА рд╣реИ?

ЁЯФ╣ Library рдПрдХ code collection рд╣реЛрддреА рд╣реИ рдЬрд┐рд╕рдореЗрдВ рдкрд╣рд▓реЗ рд╕реЗ рд▓рд┐рдЦреЗ рд╣реБрдП functions, methods рдФрд░ tools рд╣реЛрддреЗ рд╣реИрдВред рдпреЗ рдЖрдкрдХреЗ development рдХреЛ рдЖрд╕рд╛рди рдмрдирд╛рддреЗ рд╣реИрдВред

тЬЕ Examples:

ЁЯУМ Developer library рдХреЛ рдЬрд░реВрд░рдд рдкрдбрд╝рдиреЗ рдкрд░ call рдХрд░рддрд╛ рд╣реИ тАУ control developer рдХреЗ рдкрд╛рд╕ рд╣реЛрддрд╛ рд╣реИред

Framework рдХреНрдпрд╛ рд╣реЛрддрд╛ рд╣реИ?

ЁЯФ╣ Framework рдПрдХ рдкреВрд░рд╛ structure рд╣реЛрддрд╛ рд╣реИ рдЬрд┐рд╕рдореЗрдВ rules, patterns рдФрд░ flow predefined рд╣реЛрддрд╛ рд╣реИред рдЖрдкрдХреЛ рдЙрд╕реА structure рдХреЗ рдЕрдиреБрд╕рд╛рд░ рдХрд╛рдо рдХрд░рдирд╛ рд╣реЛрддрд╛ рд╣реИред

тЬЕ Examples:

ЁЯУМ Framework рдЖрдкрдХреЗ code рдХреЛ control рдХрд░рддрд╛ рд╣реИ тАУ рдпреЗ decide рдХрд░рддрд╛ рд╣реИ рдХрд┐ рдЖрдкрдХрд╛ code рдХреИрд╕реЗ рдЪрд▓реЗрдЧрд╛ред

Library vs Framework тАУ Table Comparison

ЁЯФз 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

ЁЯСитАНЁЯПл Analogy (рддреБрд▓рдирд╛)

Example Library Framework
Kitchen рдЖрдкрдиреЗ mixer grinder рд▓рд┐рдпрд╛ тАУ рдЬрдм рдЬрд░реВрд░рдд рд╣реЛ, use рдХрд░реЛ рдЖрдкрдиреЗ chef рд░рдЦрд╛ тАУ рдкреВрд░рд╛ рдХрд╛рдо chef рдЕрдкрдиреЗ рд╣рд┐рд╕рд╛рдм рд╕реЗ рдХрд░реЗрдЧрд╛

тЬЕ Real-world Code Examples

Using Library (React):

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.

Using Framework (Angular):

@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 рд╣реИ рдпрд╛ Framework?

React рдПрдХ library рд╣реИ, рдЬреЛ UI рдмрдирд╛рдиреЗ рдХреЗ рд▓рд┐рдП use рд╣реЛрддреА рд╣реИред рд▓реЗрдХрд┐рди рдЬрдм рдЖрдк uske saath routing, state management рдЖрджрд┐ рдЬреЛрдбрд╝рддреЗ рд╣реИрдВ рддреЛ рдпреЗ ek framework рдЬреИрд╕рд╛ рдмрди рдЬрд╛рддрд╛ рд╣реИред

ЁЯУЪ Summary Table

Criteria Library Framework
Control Developer Framework
Use Specific Function Complete Structure
Flexibility High Low
Example React, jQuery Angular, Django

ЁЯФз React Environment Setup тАУ Beginner to Pro

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).

ЁЯзй Step 1: Install Node.js

ЁЯЦея╕П Step 2: Install Visual Studio Code (VS Code)

тЪЩя╕П Step 3: React Setup Methods

Method Tool Best For
Traditional Create React App (CRA) Beginners & Learning
Modern Vite Fast builds & advanced devs

ЁЯУж CRA Setup (Traditional)

npx create-react-app my-app
cd my-app
npm start

ЁЯЪА Opens at http://localhost:3000

тЪб Vite Setup (Modern & Fast)

ЁЯЪА React Project Setup using Vite (Full Step-by-Step)

ЁЯУБ Step-by-Step Instructions:

  1. Open CMD and choose where to create your React project.
    Example: Drive D, inside folder project
  2. Run these commands:
    cd/
    D:
    cd project
  3. Create Vite Project:
    npm create vite
    Need to install the following packages: create-vite@7.0.3 Ok to proceed? (y)
  4. Type y and press Enter
  5. Enter Project Name тЖТ e.g. singlePage
  6. Press Enter for default Package Name (same as project)
  7. Select a Framework тЖТ Use arrow keys to choose React
  8. Select a Variant тЖТ Choose JavaScript and press Enter
Scaffolding project in D:\project\singlePage... тЬФ Done. Now run: cd singlePage npm install npm run dev
  1. Type: cd singlePage
  2. Install packages:
    npm install
    added 152 packages, and audited 153 packages in 35s 33 packages are looking for funding run `npm fund` for details found 0 vulnerabilities
  3. Before running the app, open it in VS Code:
    code .
    (This works only if VS Code is properly installed and code command is available)
  4. Now run the app:
    npm run dev
    VITE v7.0.4 ready in 261 ms тЮЬ Local: http://localhost:5173/ тЮЬ Network: use --host to expose тЮЬ press h + enter to show help
  5. ЁЯСЙ Open browser and visit: http://localhost:5173/

ЁЯОЙ Congratulations!

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)

ЁЯУБ React Project Folder Structure

React JS тАФ Project Folder Structure (Hindi)

ЁЯУБ node_modules

Jab aap npm install ya yarn install chalate ho, to ye folder automatic create hota hai.

  • Isme project ki saari dependencies (React, libraries) store hoti hain.
  • Isko manually edit nahi karna chahiye.
  • Kaafi heavy hota hai тАФ isliye Git me commit nahi karte. (`.gitignore` me add karte hain)

ЁЯУБ public

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.
  • Public folder ka content "as-is" serve hota hai тАФ bundler unhe change nahi karta.

ЁЯУБ src

Yeh sabse important folder hai тАФ aapka main application code yahin hota hai.

  • assets/ тАФ images, fonts, icons, statically used assets.
  • App.jsx (ya App.js) тАФ main React component.
  • main.jsx (ya index.js) тАФ entry point: ReactDOM.render / createRoot se <App /> mount hota hai.
  • index.css тАФ global styles; App.css тАФ App-specific styles.

ЁЯУД .gitignore

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.

ЁЯУД package.json

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"
                    }
                  }
               

ЁЯУД package-lock.json / yarn.lock

Dependencies ke exact versions lock karne ke liye тАФ taaki sab developers same versions use karein.

ЁЯУД vite.config.js (agar Vite use kar rahe ho)

Bundler/Dev server configuration: aliases, plugins, optimization settings, etc.

ЁЯФС Quick classroom summary

node_modules тЖТ Library store room ЁЯУЪ
public тЖТ Directly served files ЁЯУВ
src тЖТ Real code / app ka heart ЁЯТУ
.gitignore тЖТ Git ko bolna "mat upload karo" ЁЯЪл

package.json тЖТ Project ki shopping list ЁЯЫТ
main.jsx тЖТ App start karne ka gate ЁЯЪк
App.jsx тЖТ Main ghar (UI) ЁЯПа

ЁЯУЪ Example: Minimal folder tree (presentation ke liye)


                  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
               

React JSX (JavaScript XML)

What is JSX?

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.

Note: JSX is not HTML. It just looks like HTML, but under the hood it is transformed into JavaScript.

Example of JSX

{`function App() { return (

Hello Students ЁЯСЛ

Welcome to React JSX

); }`}

Why use JSX?

Rules of JSX

{`function Demo() { const name = "Praveen"; return (

Hello, {name}

); }`}

JSX ka full form hai JavaScript XML. Ye ek special syntax hai jisme hum JavaScript ke andar HTML jaisa code likh sakte hain.

1. JSX kyun use karte hain?

2. JSX Example (Hello World)

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.

3. JSX me JavaScript ka use

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>
                 );
            }

4. JSX ke Rules

CSS vs React Inline Style (JSX)

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" }}
Tip
React inline styles use camelCase properties and values are usually strings. Numeric values without units (like lineHeight) can be numbers.
Example usage in a React component:
{`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>
                 );
            }

5. JSX ke Fayde

React Components

What is a Component?

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.

Note: In React, everything is built using components.

Types of Components

1. Functional Component Example


            function Welcome() {
              return 

Hello, Students ЁЯСЛ

; } export default Welcome;

2. Using the Component in App.js


            import Welcome from "./Welcome";
            function App() {
              return (
                
); } export default App;

3. Class Component Example (Old Style)


            import React, { Component } from "react";
            class Welcome extends Component {
              render() {
                return 

Hello, Students ЁЯСЛ (Class Component)

; } } export default Welcome;

Why use Components?

Project Structure


            my-react-app/
            тФВ
            тФЬтФА index.html
            тФЬтФА main.jsx
            тФЬтФА App.jsx
            тФЬтФА Component/
            тФВ   тФЬтФА Volu.jsx
            тФВ   тФФтФА Pk.jsx
            тФФтФА package.json
         

main.jsx

            
            // 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

                
            
            // 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;
            
         

Component/Volu.jsx (Mr Component)

            
            // 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;
            
         

Component/Pk.jsx (Add Component)

            
            // 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;
            
         

React Props

Props рдХрд╛ рдорддрд▓рдм рд╣реИ Propertiesред рдпрд╣ рдПрдХ рддрд░реАрдХрд╛ рд╣реИ рдЬрд┐рд╕рд╕реЗ рд╣рдо Parent Component рд╕реЗ Child Component рдХреЛ data рднреЗрдЬ рд╕рдХрддреЗ рд╣реИрдВред

Key Points:

Example:

// 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;

Output:

Hello, my name is Praveen and I am 22 years old.
Hello, my name is Aman and I am 21 years old.
  

Passing Multiple Properties (Props)

рдЖрдк React рдореЗрдВ рдПрдХ рд╕реЗ рдЬреНрдпрд╛рджрд╛ properties (props) рдПрдХ component рдХреЛ pass рдХрд░ рд╕рдХрддреЗ рд╣реИрдВред
рд╣рд░ attribute automatically component рдореЗрдВ object рдХреА property рдмрди рдЬрд╛рддрд╛ рд╣реИред

Key Points:

Example:

// 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>
  );
}

Output:

I have a Red Ford Mustang from 2024.
  

Props Destructuring

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 рдХрд╛ рдЗрд╕реНрддреЗрдорд╛рд▓ рдХрд░рддреЗ рд╣реИрдВред

Key Points:

Example Without 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>
  );
}

Example With Destructuring:

// 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>
  );
}

Output:

My name is Praveen, I am 22 years old and learning React.
  

Props Children

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 рдХрд┐рдпрд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИред

Key Points:

Example:

// 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;

Output:

React рдореЗрдВ, рдЖрдк рдХрд┐рд╕реА component рдХреЗ opening рдФрд░ closing tags рдХреЗ рдмреАрдЪ 
 рдХрд╛ content рджреВрд╕рд░реЗ component рдореЗрдВ рднреЗрдЬ рд╕рдХрддреЗ рд╣реИрдВред рдЗрд╕реЗ рджреВрд╕рд░реЗ
  component рдореЗрдВ props.children рдХреА рдорджрдж рд╕реЗ access рдХрд┐рдпрд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИред
// Accessing children content
  

React Events

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 { }.

Example 1: Button Click Event

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 рдХрд┐рдпрд╛ рдЧрдпрд╛ рд╣реИред

Example 2: Inline Event Handling

function InlineExample() {
  return (
    <button onClick={() => alert("Inline function triggered!")}>
      Click Inline
    </button>
  );
}

export default InlineExample;

Explanation: Separate function рдХреЗ рдмрдЬрд╛рдп arrow function рд╕реАрдзреЗ onClick рдореЗрдВ рд▓рд┐рдЦрд╛ рдЧрдпрд╛ред рдЫреЛрдЯреЗ actions рдХреЗ рд▓рд┐рдП use рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред

What is State?

рд╣рд┐рдВрджреА рдореЗрдВ рд╕рдордЭрдирд╛: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.


1я╕П ЁЯСЙ React рдореЗрдВ State manage рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рд╕рдмрд╕реЗ рдЬреНрдпрд╛рджрд╛ useState hook use рд╣реЛрддрд╛ рд╣реИред

 // 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

Step-by-Step: Counter Example тАФ рдХреНрдпрд╛ рд╣реБрдЖ рдФрд░ рдХреНрдпреЛрдВ

рдиреАрдЪреЗ React `useState` рдХреЗ рдЙрджрд╛рд╣рд░рдг рдХрд╛ рдкреВрд░рд╛ step-by-step рд╡рд┐рд╡рд░рдг рд╣реИ тАФ рд╣рд░ рд▓рд╛рдЗрди рдХреЛ рдЖрд╕рд╛рди рд╣рд┐рдВрджреА рдореЗрдВ рд╕рдордЭрд╛рдпрд╛ рдЧрдпрд╛ рд╣реИред

Step-by-Step (рдХреНрдпрд╛ рд╣реБрдЖ рдФрд░ рдХреНрдпреЛрдВ)

1. import { useState } from "react";

рдпрд╣рд╛рдБ рд╣рдо React рдХрд╛ useState hook рд▓рд╛рддреЗ рд╣реИрдВ, рдЬреЛ functional components рдореЗрдВ state рдмрдирд╛рдиреЗ рдХреЗ рдХрд╛рдо рдЖрддрд╛ рд╣реИред

2. function Counter() { ... }

рдпреЗ рдПрдХ React functional component рд╣реИред рдЬрдм рдЗрд╕реЗ render рд╣реЛрдирд╛ рд╣реЛрдЧрд╛ React рдпрд╣ function рдЪрд▓рд╛рдПрдЧрд╛ рдФрд░ JSX рд▓реМрдЯрд╛рдПрдЧрд╛ред

3. 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 рдХреЛ рд░рдЦрддрд╛ рд╣реИред

4. function increase() { setCount(count + 1); }

рдпрд╣ event handler рд╣реИред рдЬрдм рд╣рдо button рдкрд░ рдХреНрд▓рд┐рдХ рдХрд░реЗрдВрдЧреЗ, рдпреЗ function рдЪрд▓рдХрд░ setCount рдХреЛ рдмреБрд▓рд╛рдПрдЧрд╛ред

setCount(count + 1) рдХрд╛ рдорддрд▓рдм рд╣реИ: рдирдП state рдХреЗ рд▓рд┐рдП current count рдореЗрдВ 1 рдЬреЛрдбрд╝ рджреЛ рдФрд░ React рдХреЛ рдмрддрд╛рдУ state рдмрджрд▓ рдЧрдИ рд╣реИред

5. JSX return (UI)

рдиреАрдЪреЗ рд╡рд╛рд▓реЗ JSX рдореЗрдВ:

<h2>Count: {count}</h2>
<button onClick={increase}>Increase</button>

<h2> рдореЗрдВ {count} current state рджрд┐рдЦрд╛рддрд╛ рд╣реИред

onClick={increase} тАФ рдпрд╣рд╛рдБ рд╣рдо function рдХрд╛ reference рджреЗ рд░рд╣реЗ рд╣реИрдВ (рдЗрд╕реЗ рдХреЙрд▓ рдирд╣реАрдВ рдХрд░ рд░рд╣реЗ)ред рдмреНрд░рд╛рдЙрдЬрд╝рд░ click рд╣реЛрдиреЗ рдкрд░ React рдпрд╣ function рдЪрд▓рд╛рдПрдЧрд╛ред

6. Initial Render flow

React Counter() call рдХрд░рддрд╛ рд╣реИ тЖТ useState(0) рджреЗрддрд╛ рд╣реИ тЖТ component JSX рд▓реМрдЯрддрд╛ рд╣реИ тЖТ Browser рдореЗрдВ DOM mount рд╣реЛрддрд╛ рд╣реИ тЖТ рдЖрдк рджреЗрдЦрддреЗ рд╣реИрдВ: Count: 0 рдФрд░ рдПрдХ Increase buttonред

7. рдЬрдм user 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 (рдкрд╣рд▓реА рдХреНрд▓рд┐рдХ рдХреЗ рдмрд╛рдж)ред

8. рдмрд╛рд░-рдмрд╛рд░ рдХреНрд▓рд┐рдХ рдХрд░рдиреЗ рдкрд░

рд╣рд░ 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 рди рдЖрдПред

рдпрд╣ рдкреЗрдЬ students рдХреЗ рд▓рд┐рдП рддреИрдпрд╛рд░ рдХрд┐рдпрд╛ рдЧрдпрд╛ рд╣реИ тАФ рдЗрд╕реЗ print рдХрд░рдХреЗ рдпрд╛ classroom рдореЗрдВ рджрд┐рдЦрд╛рдХрд░ рдЙрдкрдпреЛрдЧ рдХрд░ рд╕рдХрддреЗ рд╣реИрдВред

          
         // 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

рд╣рд┐рдВрджреА рдореЗрдВ рд╕рдордЭрдирд╛: React рдореЗрдВ Conditional Rendering рдХрд╛ рдорддрд▓рдм рд╣реИ рдХрд┐ рдХрд┐рд╕реА condition рдХреЗ рдЖрдзрд╛рд░ рдкрд░ component рдХрд╛ рдХреБрдЫ рд╣рд┐рд╕реНрд╕рд╛ рджрд┐рдЦрд╛рдирд╛ рдпрд╛ рдирд╣реАрдВ рджрд┐рдЦрд╛рдирд╛ред

English Notes: Conditional Rendering in React means rendering components or elements based on certain conditions.

1я╕ПтГг Using if/else Statement


   // 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:

2я╕ПтГг Using Ternary Operator


function Greeting(props) {
  return (
    <div>
      {props.isLoggedIn ? <h2>Welcome back!</h2> : <h2>Please log in.</h2>}
    </div>
  );
}

export default Greeting;

Explanation:

3я╕ПтГг Using Logical AND (&&)


function Message(props) {
  const isLoggedIn = props.isLoggedIn;

  return (
    <div>
      {isLoggedIn && <h2>Welcome back!</h2>}
    </div>
  );
}

export default Message;

Explanation:

Summary / Notes

React Lists

рд╣рд┐рдВрджреА рдореЗрдВ рд╕рдордЭрдирд╛: 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.

1я╕ПтГг Basic Example

imp : syntax :: {const_names.map((conat_name) => ( write code here those you want in loop ))}

function NameList() {
  const names = ["Praveen", "Pankaj", "Neha"];

  return (
    <ul>
      {names.map((name) => (
        <li>{name}</li>
      ))}
    </ul>
  );
}

export default NameList;

Explanation:

1я╕ПтГг React Forms рдХреНрдпрд╛ рд╣реИрдВ?

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.

2я╕ПтГг Controlled Component рдХреНрдпрд╛ рд╣реИ?

Hindi: рдЬрдм input рдХрд╛ value React state рдХреЗ рджреНрд╡рд╛рд░рд╛ control рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ рддреЛ рдЙрд╕реЗ controlled component рдХрд╣рддреЗ рд╣реИрдВред

English: A controlled component is a form element whose value is controlled by React state.

Example: Single Input

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;

Step-by-Step Explanation

  1. State Create: const [name, setName] = useState(""); - input value store рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдПред
  2. handleChange: input typing рдкрд░ state update рдХрд░рддрд╛ рд╣реИред
  3. handleSubmit: form submit рдкрд░ default reload рд░реЛрдХрддрд╛ рд╣реИ рдФрд░ value alert рджрд┐рдЦрд╛рддрд╛ рд╣реИред
  4. JSX Input: value={name} + onChange={handleChange} тЖТ controlled componentред
  5. Submit Button: onSubmit trigger рдХрд░рддрд╛ рд╣реИред

3я╕ПтГг Multiple Input Fields

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;

4я╕ПтГг Select Dropdown Example

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;

5я╕ПтГг Key Notes

Summary Table

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

React Forms тАУ Handling Checkbox (Checkbox рдХреНрдпрд╛ рд╣реЛрддрд╛ рд╣реИ?)

рд╣рд┐рдВрджреА рдореЗрдВ рд╕рдордЭрдирд╛: 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.

1я╕ПтГг Basic Example


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:

2я╕ПтГг Multiple Checkboxes Example


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:

3я╕ПтГг Key Notes

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

4я╕ПтГг Summary

React Forms тАУ Handling Radio Buttons (Radio Button рдХреНрдпрд╛ рд╣реЛрддрд╛ рд╣реИ?)

рд╣рд┐рдВрджреА рдореЗрдВ рд╕рдордЭрдирд╛: Radio buttons рдПрдХ form element рд╣реЛрддреЗ рд╣реИрдВ рдЬреЛ user рдХреЛ рдПрдХ group рдореЗрдВ рд╕реЗ рдХреЗрд╡рд▓ рдПрдХ option рдЪреБрдирдиреЗ рдХреА рдЕрдиреБрдорддрд┐ рджреЗрддреЗ рд╣реИрдВред

English Notes: Radio buttons allow users to select only one option from a predefined group.

1я╕ПтГг Basic Example


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:

2я╕ПтГг Key Notes

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

3я╕ПтГг Summary

React Portals (React Portal рдХреНрдпрд╛ рд╣реЛрддрд╛ рд╣реИ?)

рд╣рд┐рдВрджреА рдореЗрдВ рд╕рдордЭрдирд╛: 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.

1я╕ПтГг Why Use Portals?

2я╕ПтГг Example: Simple Modal Using React Portal


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;

3я╕ПтГг App.jsx Example


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;

4я╕ПтГг index.html (Important)

Portals рдХреЛ рдХрд╛рдо рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП, index.html рдореЗрдВ рдПрдХ extra div рдЪрд╛рд╣рд┐рдП:


<div id="root"></div>
<div id="modal-root"></div>  <!-- Modal рдпрд╣реА render рд╣реЛрдЧрд╛ -->

5я╕ПтГг Step-by-Step Explanation

6я╕ПтГг Result

7я╕ПтГг Key Points

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

8я╕ПтГг Summary

React Suspense (React Suspense рдХреНрдпрд╛ рд╣реИ?)

рд╣рд┐рдВрджреА рдореЗрдВ: 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.

1я╕ПтГг Basic Example: Lazy Loading Component


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;

  

2я╕ПтГг LazyComponent.jsx


function LazyComponent() {
  return <h2>Hello! I am loaded lazily. ЁЯОЙ</h2>;
}

export default LazyComponent;
  

3я╕ПтГг Step-by-Step Explanation

4я╕ПтГг Key Points

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

5я╕ПтГг Summary

Styling React Using CSS (React рдореЗрдВ CSS Styling)

рд╣рд┐рдВрджреА рдореЗрдВ: 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.

1я╕ПтГг Inline Styling

Hindi: Inline style attribute рдореЗрдВ styling рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП value рд╣рдореЗрд╢рд╛ JavaScript object рд╣реЛрддреА рд╣реИред

English: Inline styles require a JavaScript object as the value.

Example 1: Simple Inline Style


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 {{}} рд╣реЛрддреЗ рд╣реИрдВред

Example 2: camelCased Property Names


const Header = () => {
  return (
    <>
      <h1 style={{backgroundColor: "lightblue"}}>Hello Style!</h1>
      <p>Add a little style!</p>
    </>
  );
}
  

Example 3: JavaScript Object


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>
    </>
  );
}
  

2я╕ПтГг CSS Stylesheet

Hindi: CSS рдХреЛ рдЕрд▓рдЧ .css file рдореЗрдВ рд▓рд┐рдЦреЗрдВ рдФрд░ component рдореЗрдВ import рдХрд░реЗрдВред

English: Write CSS in a separate .css file and import it in your component.

Example:


/* 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 />
);
  

3я╕ПтГг CSS Modules

Hindi: Components рдХреЗ рд▓рд┐рдП local scope stylingред Name conflicts рд╕реЗ рдмрдЪрд╛рддрд╛ рд╣реИред

English: Provides local scoped styling for components, preventing name conflicts.

Example:


/* 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 />
);
  

4я╕ПтГг Key Points

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

5я╕ПтГг Summary

React CSS Modules (React рдореЗрдВ CSS Modules)

рд╣рд┐рдВрджреА рдореЗрдВ: 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.

1я╕ПтГг Create a CSS Module File

CSS Module file рдХрд╛ рдирд╛рдо рд╣рдореЗрд╢рд╛ *.module.css рд╣реЛрдирд╛ рдЪрд╛рд╣рд┐рдПред


/* my-style.module.css */
.bigred {
  color: Tomato;
  padding: 40px;
  font-family: Sans-Serif;
  text-align: center;
}
  

2я╕ПтГг Import CSS Module in Component


import styles from './my-style.module.css';

const Car = () => {
  return <h1 className={styles.bigred}>Hello Car!</h1>;
}

export default Car;
  

3я╕ПтГг Key Features of CSS Modules

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

4я╕ПтГг Step-by-Step Explanation

5я╕ПтГг Summary

React CSS-in-JS (React рдореЗрдВ CSS-in-JS)

рд╣рд┐рдВрджреА рдореЗрдВ: 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.

1я╕ПтГг Example using Inline Styles (Basic CSS-in-JS)


const Header = () => {
  const style = {
    color: "white",
    backgroundColor: "DodgerBlue",
    padding: "10px",
    borderRadius: "5px",
    textAlign: "center"
  };

  return <h1 style={style}>Hello CSS-in-JS!</h1>;
}
  

2я╕ПтГг Example using styled-components


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;
  

3я╕ПтГг Key Features of CSS-in-JS

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

4я╕ПтГг Step-by-Step Explanation

5я╕ПтГг Summary

React Router (React рдореЗрдВ Routing)

рд╣рд┐рдВрджреА рдореЗрдВ: 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.

1я╕ПтГг Why React Router?

2я╕ПтГг Installation

npm install react-router-dom

3я╕ПтГг Basic Setup


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;
  

4я╕ПтГг Step-by-Step Explanation

5я╕ПтГг Nested Routes

рдЖрдк 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>
  );
}
  

6я╕ПтГг Active Links (NavLink)

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>
  

7я╕ПтГг URL Parameters

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 /> />
  

8я╕ПтГг Summary

React Hooks (React рдореЗрдВ Hooks)

рд╣рд┐рдВрджреА рдореЗрдВ: 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.

1я╕ПтГг What Are Hooks?

2я╕ПтГг Why Use Hooks?

3я╕ПтГг Commonly Used React Hooks

4я╕ПтГг useState Hook

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;
  

5я╕ПтГг useEffect Hook

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>
  );
}
  

6я╕ПтГг useContext Hook

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>
  );
}
  

7я╕ПтГг useRef Hook

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>
  );
}
  

8я╕ПтГг useMemo Hook

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>
  );
}
  

9я╕ПтГг useCallback Hook

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>
  );
}
  

ЁЯФЯ Rules of Hooks

тЬЕ Summary