TGViewer
Web Development Web Development @webdevcoursefree · 79.6K subscribers
Post #3530 4.93K
⚛️ React Basics (Components, Props, State)

Now you move from simple websites → modern frontend apps.

React is used in real companies like Netflix, Facebook, Airbnb.

⚛️ What is React 
React is a JavaScript library for building UI. 
👉 Developed by Facebook 
👉 Used to build fast interactive apps 
👉 Component-based architecture 
Simple meaning 
• Break UI into small reusable pieces
Example 
• Navbar → component
• Card → component
• Button → component

🧱 Why React is Used 
Without React 
• DOM updates become complex
• Code becomes messy
React solves: 
✅ Faster UI updates (Virtual DOM) 
✅ Reusable components 
✅ Clean structure 
✅ Easy state management 

🧩 Core Concept 1: Components 
❓ What is a component 
A component is a reusable UI block. 
Think like LEGO blocks. 

✍️ Simple React Component 
function Welcome() {
    return <h1>Hello User</h1>;
}

Use component 
<Welcome />


📦 Types of Components 
🔹 Functional Components (Most Used) 
function Header() {
    return <h1>My Website</h1>;
}
 
🔹 Class Components (Old) 
Less used today. 

✅ Why components matter 
• Reusable code
• Easy maintenance
• Clean structure

📤 Core Concept 2: Props (Passing Data) 
❓ What are props 
Props = data passed to components. 
Parent → Child communication. 

Example 
function Welcome(props) {
    return <h1>Hello {props.name}</h1>;
}

Use 
<Welcome name="Deepak" />

Output 👉 Hello Deepak 

🧠 Props Rules 
• Read-only
• Cannot modify inside component
• Used for customization

🔄 Core Concept 3: State (Dynamic Data) 
❓ What is state 
State stores changing data inside component. 
If state changes → UI updates automatically. 

Example using useState 
import { useState } from "react";
function Counter() {
    const [count, setCount] = useState(0);
    return (
        <div>
            <p>{count}</p>
            <button onClick={() => setCount(count + 1)}>
                Increase
            </button>
        </div>
    );
}


🧠 How state works 
• count → current value
• setCount() → update value
• UI re-renders automatically
This is React’s biggest power. 

⚖️ Props vs State (Important Interview Question) 
| Props | State |
|-------|-------|
| Passed from parent | Managed inside component |
| Read-only | Can change |
| External data | Internal data |

⚠️ Common Beginner Mistakes 
• Modifying props
• Forgetting import of useState
• Confusing props and state
• Not using components properly

🧪 Mini Practice Task 
• Create a component that shows your name
• Pass name using props
• Create counter using state
• Add button to increase count

✅ Mini Practice Task – Solution

🟦 1️⃣ Create a component that shows your name 
function MyName() {
    return <h2>My name is Deepak</h2>;
}
export default MyName;

✔ Simple reusable component 
✔ Displays static text 

📤 2️⃣ Pass name using props 
function Welcome(props) {
    return <h2>Hello {props.name}</h2>;
}
export default Welcome;

Use inside App.js 
<Welcome name="Deepak" />

✔ Parent sends data 
✔ Component displays dynamic value 

🔄 3️⃣ Create counter using state 
import { useState } from "react";
function Counter() {
    const [count, setCount] = useState(0);
    return <h2>Count: {count}</h2>;
}
export default Counter;

✔ State stores changing value 
✔ UI updates automatically 

➕ 4️⃣ Add button to increase count 
import { useState } from "react";
function Counter() {
    const [count, setCount] = useState(0);
    return (
        <div>
            <h2>Count: {count}</h2>
            <button onClick={() => setCount(count + 1)}>
                Increase
            </button>
        </div>
    );
}
export default Counter;

✔ Click → state updates → UI re-renders 

🧩 How to use everything in App.js

import MyName from "./MyName";
import Welcome from "./Welcome";
import Counter from "./Counter";

function App() {
    return (
        <div>
            <MyName />
            <Welcome name="Deepak" />
            <Counter />
        </div>
    );
}
export default App;


➡️ Double Tap ♥️ For More
  • ❤ 34
  • 🥰 4
  • 🔥 1
More from @webdevcoursefree
  1. Oct 14, 2026🌐 Web Development Roadmap — Part 17 HTML Images — <img> Tag Images make webpages more vis…
  2. Oct 13, 2026𝗧𝗢𝗣 𝗙𝗥𝗘𝗘 𝗖𝗢𝗨𝗥𝗦𝗘𝗦 𝗧𝗢 𝗕𝗢𝗢𝗦𝗧 𝗬𝗢𝗨𝗥 𝗦𝗞𝗜𝗟𝗟𝗦 𝗜𝗡 𝟮𝟬𝟮𝟲! Explor…
  3. Oct 12, 2026For example: Go to Profile → <a> Submit Form → <button> Open Article → <a> Delete Account…
  4. Oct 12, 2026🌐 Web Development Roadmap — Part 16 HTML Links — Tag Links are one of the most important…
  5. Oct 12, 2026🚀 𝗪𝗵𝗶𝗰𝗵 𝗧𝗲𝗰𝗵 𝗦𝗸𝗶𝗹𝗹 𝗪𝗶𝗹𝗹 𝗬𝗼𝘂 𝗠𝗮𝘀𝘁𝗲𝗿 𝗶𝗻 𝟮𝟬𝟮𝟲? Want to buil…
  6. Oct 9, 2026Post #4079
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →