Now, let's move to the next topic in Web Development Roadmap:
*βοΈ 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*
*βοΈ 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*
β€1
Backend Development Live Batch is Now Open!
If youβre serious about building real-world backend skills, this is for you.
Iβm starting a job-oriented live training program on:
π Node.js | Express.js | MongoDB
π₯ Special Launch Offer: 90% OFF β Just βΉ4,999/-
π Live classes: 3 days a week | 2 hours per session
π― Focus on practical projects, APIs, authentication & deployment
β³ Offer valid for only 2 days
This program is for students & developers who want to move from tutorials to industry-ready backend skills.
π© mail at: mohitdecode@gmail.com
If youβre serious about building real-world backend skills, this is for you.
Iβm starting a job-oriented live training program on:
π Node.js | Express.js | MongoDB
π₯ Special Launch Offer: 90% OFF β Just βΉ4,999/-
π Live classes: 3 days a week | 2 hours per session
π― Focus on practical projects, APIs, authentication & deployment
β³ Offer valid for only 2 days
This program is for students & developers who want to move from tutorials to industry-ready backend skills.
π© mail at: mohitdecode@gmail.com
Check Any Element greater than 100 | some() - Javascript Interview #dsa #interview #coding
https://youtube.com/shorts/lA5vV3ImRxg?feature=share
https://youtube.com/shorts/lA5vV3ImRxg?feature=share
YouTube
Check Any Element greater than 100 | some() - Javascript Interview #dsa #interview #coding
Check if any element in an array is greater than 100 interview question explained using the some() method in JavaScript.In this short video, you will learn h...
β€1
*π€ AβZ of Web Development* π
*A β API*
Set of rules allowing different apps to communicate, like fetching data from servers.
*B β Bootstrap*
Popular CSS framework for responsive, mobile-first front-end development.
*C β CSS*
Styles web pages with layouts, colors, fonts, and animations for visual appeal.
*D β DOM*
Document Object Model; tree structure representing HTML for dynamic manipulation.
*E β ES6+*
Modern JavaScript features like arrows, promises, and async/await for cleaner code.
*F β Flexbox*
CSS layout module for one-dimensional designs, aligning items efficiently.
*G β GitHub*
Platform for version control and collaboration using Git repositories.
*H β HTML*
Markup language structuring content with tags for headings, links, and media.
*I β IDE*
Integrated Development Environment like VS Code for coding, debugging, tools.
*J β JavaScript*
Language adding interactivity, from form validation to full-stack apps.
*K β Kubernetes*
Orchestration tool managing containers for scalable web app deployment.
*L β Local Storage*
Browser API storing key-value data client-side, persisting across sessions.
*M β MongoDB*
NoSQL database for flexible, JSON-like document storage in MEAN stack.
*N β Node.js*
JavaScript runtime for server-side; powers back-end with npm ecosystem.
*O β OAuth*
Authorization protocol letting apps access user data without passwords.
*P β Progressive Web App*
Web apps behaving like natives: offline, push notifications, installable.
*Q β Query Selector*
JavaScript/DOM method targeting elements with CSS selectors for manipulation.
*R β React*
JavaScript library for building reusable UI components and single-page apps.
*S β SEO*
Search Engine Optimization improving site visibility via keywords, speed.
*T β TypeScript*
Superset of JS adding types for scalable, error-free large apps.
*U β UI/UX*
User Interface design and User Experience focusing on usability, accessibility.
*V β Vue.js*
Progressive JS framework for reactive, component-based UIs.
*W β Webpack*
Module bundler processing JS, assets into optimized static files.
*X β XSS*
Cross-Site Scripting vulnerability injecting malicious scripts into web pages.
*Y β YAML*
Human-readable format for configs like Docker Compose or GitHub Actions.
*Z β Zustand*
Lightweight state management for React apps, simpler than Redux.
*Double Tap β₯οΈ For More*
*A β API*
Set of rules allowing different apps to communicate, like fetching data from servers.
*B β Bootstrap*
Popular CSS framework for responsive, mobile-first front-end development.
*C β CSS*
Styles web pages with layouts, colors, fonts, and animations for visual appeal.
*D β DOM*
Document Object Model; tree structure representing HTML for dynamic manipulation.
*E β ES6+*
Modern JavaScript features like arrows, promises, and async/await for cleaner code.
*F β Flexbox*
CSS layout module for one-dimensional designs, aligning items efficiently.
*G β GitHub*
Platform for version control and collaboration using Git repositories.
*H β HTML*
Markup language structuring content with tags for headings, links, and media.
*I β IDE*
Integrated Development Environment like VS Code for coding, debugging, tools.
*J β JavaScript*
Language adding interactivity, from form validation to full-stack apps.
*K β Kubernetes*
Orchestration tool managing containers for scalable web app deployment.
*L β Local Storage*
Browser API storing key-value data client-side, persisting across sessions.
*M β MongoDB*
NoSQL database for flexible, JSON-like document storage in MEAN stack.
*N β Node.js*
JavaScript runtime for server-side; powers back-end with npm ecosystem.
*O β OAuth*
Authorization protocol letting apps access user data without passwords.
*P β Progressive Web App*
Web apps behaving like natives: offline, push notifications, installable.
*Q β Query Selector*
JavaScript/DOM method targeting elements with CSS selectors for manipulation.
*R β React*
JavaScript library for building reusable UI components and single-page apps.
*S β SEO*
Search Engine Optimization improving site visibility via keywords, speed.
*T β TypeScript*
Superset of JS adding types for scalable, error-free large apps.
*U β UI/UX*
User Interface design and User Experience focusing on usability, accessibility.
*V β Vue.js*
Progressive JS framework for reactive, component-based UIs.
*W β Webpack*
Module bundler processing JS, assets into optimized static files.
*X β XSS*
Cross-Site Scripting vulnerability injecting malicious scripts into web pages.
*Y β YAML*
Human-readable format for configs like Docker Compose or GitHub Actions.
*Z β Zustand*
Lightweight state management for React apps, simpler than Redux.
*Double Tap β₯οΈ For More*
β€1
NextJS Tutorial #16 - Static vs Dynamic Server Components
https://youtu.be/o3fzTKCHnpA
https://youtu.be/o3fzTKCHnpA
YouTube
NextJS Tutorial #16 - Static vs Dynamic Server Components
This video explains the basics of data fetching in Next.js using Server Components with the App Router.
You will learn why server-side data fetching is important, how to use fetch() in Server Components, and the difference between static and dynamic dataβ¦
You will learn why server-side data fetching is important, how to use fetch() in Server Components, and the difference between static and dynamic dataβ¦
β€1
Count Vowels in String | Regex Shortcut - JavaScript Interview Question #dsa #interview #coding
https://youtube.com/shorts/FlInEjKOq6g?feature=share
https://youtube.com/shorts/FlInEjKOq6g?feature=share
YouTube
Count Vowels in String | Regex Shortcut - JavaScript Interview Question #dsa #interview #coding
Count vowels in a string interview question explained using Regex + match() in JavaScript.In this short video, you will learn a shortcut way to count vowels ...
β€1
DSA #24 - Core Data Structures | Stack β Introduction
https://youtu.be/aVI87AHOUM0
https://youtu.be/aVI87AHOUM0
YouTube
DSA #24 - Core Data Structures | Stack β Introduction
DSA Phase-3 Core Data Structures tutorial focusing on Stack.
In this video you will learn what a Stack data structure is, how the LIFO principle works, and how to implement stack operations in JavaScript.
We will cover push, pop, and peek operations withβ¦
In this video you will learn what a Stack data structure is, how the LIFO principle works, and how to implement stack operations in JavaScript.
We will cover push, pop, and peek operations withβ¦
β€2
Remove All Spaces from String | Regex - Javascript Interview #dsa #interview #coding
https://youtube.com/shorts/5ym7bMLsNAI?feature=share
https://youtube.com/shorts/5ym7bMLsNAI?feature=share
YouTube
Remove All Spaces from String | Regex - Javascript Interview #dsa #interview #coding
Remove all spaces from a string interview question explained using Regex in JavaScript.In this short video, you will learn a one-liner way to remove spaces, ...
β€1
NextJS Tutorial #18 - Loading, Error & 404 Pages
https://youtu.be/yY6mO-cx5Nw
https://youtu.be/yY6mO-cx5Nw
YouTube
NextJS Tutorial #18 - Loading, Error & 404 Pages
This video explains how to handle loading states, errors, and not found pages in the Next.js App Router to improve route-level user experience.
You will learn how loading.tsx is used to show loading UI, how error.tsx works as an error boundary, and how notβ¦
You will learn how loading.tsx is used to show loading UI, how error.tsx works as an error boundary, and how notβ¦
β€2
React and JavaScript Developer Mock Interview | FRESHER | Real Interview Questions
https://youtu.be/pAitCb3BxdQ
https://youtu.be/pAitCb3BxdQ
β€1
DSA #25 - Core Data Structures | Stack Implementation
https://youtu.be/LG5Ehs18DRs
https://youtu.be/LG5Ehs18DRs
YouTube
DSA #25 - Core Data Structures | Stack Implementation
DSA Phase-3 Core Data Structures tutorial focusing on Stack implementation using an array in JavaScript.
In this video you will learn how to implement a Stack from scratch, understand push, pop, and peek methods, and add utility methods like isEmpty and size.β¦
In this video you will learn how to implement a Stack from scratch, understand push, pop, and peek methods, and add utility methods like isEmpty and size.β¦
β€1
Now, let's move to the next topic in Web Development Roadmap:
*βοΈ Simple CRUD UI in React*
Now you learn how real apps work.
π CRUD = Create, Read, Update, Delete
Every real application uses CRUD.
Examples
- Add task β Create
- View tasks β Read
- Edit task β Update
- Delete task β Delete
*πΉ What is CRUD in React*
CRUD means managing data using UI.
React handles CRUD using:
β State
β Events
β Components
*π§ Why CRUD is Important*
- Used in dashboards
- Used in admin panels
- Used in e-commerce apps
- Top interview question
If you know CRUD β you can build real apps.
*π§© Example Project: Todo List CRUD*
We will build:
β Add item
β Show item
β Delete item
β Update item
*βοΈ Step 1: Setup State*
State stores list data.
import { useState } from "react";
function App() {
const [items, setItems] = useState([]);
return <div></div>;
}
export default App;
β items β list data
β setItems() β update list
*β Step 2: Create (Add Item)*
Add new item to list.
const [input, setInput] = useState("");
const addItem = () => {
setItems([...items, input]);
setInput("");
};
UI
<input value={input} onChange={(e) => setInput(e.target.value)} />
<button onClick={addItem}>Add</button>
*π Step 3: Read (Show Items)*
Display list using map.
<ul>
{items.map((item, index) => (
<li key={index}>{item}</li>
))}
</ul>
*β Step 4: Delete Item*
Remove item from list.
const deleteItem = (index) => {
const newItems = items.filter((_, i) => i !== index);
setItems(newItems);
};
UI
<button onClick={() => deleteItem(index)}>Delete</button>
*βοΈ Step 5: Update Item (Edit)*
Update existing data.
const updateItem = (index) => {
const newValue = prompt("Update item");
const updated = [...items];
updated[index] = newValue;
setItems(updated);
};
UI
<button onClick={() => updateItem(index)}>Edit</button>
*β Complete CRUD UI Example*
import { useState } from "react";
function App() {
const [items, setItems] = useState([]);
const [input, setInput] = useState("");
const addItem = () => {
if (!input) return;
setItems([...items, input]);
setInput("");
};
const deleteItem = (index) => {
setItems(items.filter((_, i) => i !== index));
};
const updateItem = (index) => {
const newValue = prompt("Update item");
if (!newValue) return;
const updated = [...items];
updated[index] = newValue;
setItems(updated);
};
return (
<div>
<h2>Todo CRUD</h2>
<input value={input} onChange={(e) => setInput(e.target.value)} />
<button onClick={addItem}>Add</button>
<ul>
{items.map((item, index) => (
<li key={index}>
{item}
<button onClick={() => updateItem(index)}>Edit</button>
<button onClick={() => deleteItem(index)}>Delete</button>
</li>
))}
</ul>
</div>
);
}
export default App;
*π§ How CRUD Works Internally*
- User action β event triggers
- State updates
- React re-renders UI
This is Reactβs core workflow.
*β οΈ Common Beginner Mistakes*
- Mutating state directly
- Forgetting key in list
- Not copying arrays before update
- Confusing state updates
*π§ͺ Mini Practice Task*
- Build a simple student list CRUD
- Add student name
- Edit student name
- Delete student
- Show total count
*β Mini Practice Task β Solution βοΈ*
This covers:
β Add student
β Edit student
β Delete student
β Show total count
*π§© Complete Working Example*
import { useState } from "react";
function App() {
const [students, setStudents] = useState([]);
const [input, setInput] = useState("");
// β Add Student
const addStudent = () => {
if (!input.trim()) return;
setStudents([...students, input]);
setInput("");
};
// β Delete Student
const deleteStudent = (index) => {
const updated = students.filter((_, i) => i !== index);
setStudents(updated);
};
// βοΈ Edit Student
const editStudent = (index) => {
const newName = prompt("Enter new name");
if (!newName || !newName.trim()) return;
const updated = [...students];
*βοΈ Simple CRUD UI in React*
Now you learn how real apps work.
π CRUD = Create, Read, Update, Delete
Every real application uses CRUD.
Examples
- Add task β Create
- View tasks β Read
- Edit task β Update
- Delete task β Delete
*πΉ What is CRUD in React*
CRUD means managing data using UI.
React handles CRUD using:
β State
β Events
β Components
*π§ Why CRUD is Important*
- Used in dashboards
- Used in admin panels
- Used in e-commerce apps
- Top interview question
If you know CRUD β you can build real apps.
*π§© Example Project: Todo List CRUD*
We will build:
β Add item
β Show item
β Delete item
β Update item
*βοΈ Step 1: Setup State*
State stores list data.
import { useState } from "react";
function App() {
const [items, setItems] = useState([]);
return <div></div>;
}
export default App;
β items β list data
β setItems() β update list
*β Step 2: Create (Add Item)*
Add new item to list.
const [input, setInput] = useState("");
const addItem = () => {
setItems([...items, input]);
setInput("");
};
UI
<input value={input} onChange={(e) => setInput(e.target.value)} />
<button onClick={addItem}>Add</button>
*π Step 3: Read (Show Items)*
Display list using map.
<ul>
{items.map((item, index) => (
<li key={index}>{item}</li>
))}
</ul>
*β Step 4: Delete Item*
Remove item from list.
const deleteItem = (index) => {
const newItems = items.filter((_, i) => i !== index);
setItems(newItems);
};
UI
<button onClick={() => deleteItem(index)}>Delete</button>
*βοΈ Step 5: Update Item (Edit)*
Update existing data.
const updateItem = (index) => {
const newValue = prompt("Update item");
const updated = [...items];
updated[index] = newValue;
setItems(updated);
};
UI
<button onClick={() => updateItem(index)}>Edit</button>
*β Complete CRUD UI Example*
import { useState } from "react";
function App() {
const [items, setItems] = useState([]);
const [input, setInput] = useState("");
const addItem = () => {
if (!input) return;
setItems([...items, input]);
setInput("");
};
const deleteItem = (index) => {
setItems(items.filter((_, i) => i !== index));
};
const updateItem = (index) => {
const newValue = prompt("Update item");
if (!newValue) return;
const updated = [...items];
updated[index] = newValue;
setItems(updated);
};
return (
<div>
<h2>Todo CRUD</h2>
<input value={input} onChange={(e) => setInput(e.target.value)} />
<button onClick={addItem}>Add</button>
<ul>
{items.map((item, index) => (
<li key={index}>
{item}
<button onClick={() => updateItem(index)}>Edit</button>
<button onClick={() => deleteItem(index)}>Delete</button>
</li>
))}
</ul>
</div>
);
}
export default App;
*π§ How CRUD Works Internally*
- User action β event triggers
- State updates
- React re-renders UI
This is Reactβs core workflow.
*β οΈ Common Beginner Mistakes*
- Mutating state directly
- Forgetting key in list
- Not copying arrays before update
- Confusing state updates
*π§ͺ Mini Practice Task*
- Build a simple student list CRUD
- Add student name
- Edit student name
- Delete student
- Show total count
*β Mini Practice Task β Solution βοΈ*
This covers:
β Add student
β Edit student
β Delete student
β Show total count
*π§© Complete Working Example*
import { useState } from "react";
function App() {
const [students, setStudents] = useState([]);
const [input, setInput] = useState("");
// β Add Student
const addStudent = () => {
if (!input.trim()) return;
setStudents([...students, input]);
setInput("");
};
// β Delete Student
const deleteStudent = (index) => {
const updated = students.filter((_, i) => i !== index);
setStudents(updated);
};
// βοΈ Edit Student
const editStudent = (index) => {
const newName = prompt("Enter new name");
if (!newName || !newName.trim()) return;
const updated = [...students];
updated[index] = newName;
setStudents(updated);
};
return (
<div style={{ padding: "40px", fontFamily: "Arial" }}>
<h2>Student CRUD</h2>
{/* Input Section */}
<input
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder="Enter student name"
/>
<button onClick={addStudent}>Add</button>
{/* Total Count */}
<p>Total Students: {students.length}</p>
{/* Student List */}
<ul>
{students.map((student, index) => (
<li key={index}>
{student}
<button onClick={() => editStudent(index)}>Edit</button>
<button onClick={() => deleteStudent(index)}>Delete</button>
</li>
))}
</ul>
</div>
);
}
export default App;
*π§ What You Learned*
β Managing list using state
β Adding data using spread operator
β Updating array safely
β Filtering data to delete
β Rendering list with .map()
β Showing dynamic count
*β οΈ Interview Insight*
If interviewer asks:
π Why use [...students] before updating?
Answer: Because React state must not be mutated directly. We create a new copy to trigger re-render.
*Double Tap β₯οΈ For More*
setStudents(updated);
};
return (
<div style={{ padding: "40px", fontFamily: "Arial" }}>
<h2>Student CRUD</h2>
{/* Input Section */}
<input
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder="Enter student name"
/>
<button onClick={addStudent}>Add</button>
{/* Total Count */}
<p>Total Students: {students.length}</p>
{/* Student List */}
<ul>
{students.map((student, index) => (
<li key={index}>
{student}
<button onClick={() => editStudent(index)}>Edit</button>
<button onClick={() => deleteStudent(index)}>Delete</button>
</li>
))}
</ul>
</div>
);
}
export default App;
*π§ What You Learned*
β Managing list using state
β Adding data using spread operator
β Updating array safely
β Filtering data to delete
β Rendering list with .map()
β Showing dynamic count
*β οΈ Interview Insight*
If interviewer asks:
π Why use [...students] before updating?
Answer: Because React state must not be mutated directly. We create a new copy to trigger re-render.
*Double Tap β₯οΈ For More*
β€1
NextJS Tutorial #19 - Page & Layout SEO Metadata | Open Graph, Twitter
https://youtu.be/KmSVE47mHFI
https://youtu.be/KmSVE47mHFI
YouTube
NextJS Tutorial #19 - Page & Layout SEO Metadata | Open Graph, Twitter
This video explains how to implement SEO in Next.js using the Metadata API with the App Router.
You will learn how to add page-level metadata, layout-level metadata, and dynamic metadata for SEO-friendly pages. We also cover how to set up Open Graph andβ¦
You will learn how to add page-level metadata, layout-level metadata, and dynamic metadata for SEO-friendly pages. We also cover how to set up Open Graph andβ¦
β€1
Implement Debounce - Javascript Interview #dsa #interview #coding
https://youtube.com/shorts/x3RMM51Twzg?feature=share
https://youtube.com/shorts/x3RMM51Twzg?feature=share
YouTube
Implement Debounce - Javascript Interview #dsa #interview #coding
Implement Debounce in JavaScript with clear output explanation.In this short video, we solve a common frontend interview question:How to control rapid functi...
β€1
DSA #26 - Core Data Structures | Valid Parentheses Using Stack
https://youtu.be/Jz07KyhZK5E
https://youtu.be/Jz07KyhZK5E
YouTube
DSA #26 - Core Data Structures | Valid Parentheses Using Stack
DSA Phase-3 Core Data Structures tutorial focusing on solving the Valid Parentheses problem using Stack.
In this video you will learn how to understand the problem, apply a stack-based approach, and validate parentheses with a clear step-by-step dry run.β¦
In this video you will learn how to understand the problem, apply a stack-based approach, and validate parentheses with a clear step-by-step dry run.β¦
β€1
Now, let's move to the next topic in Web Development Roadmap:
*βοΈ React Hooks (useEffect & useRef)*
π Now you learn how React handles side effects and DOM access. These hooks are heavily used in real projects and interviews.
*π§ What are React Hooks*
Hooks let you use React features inside functional components.
Before hooks β class components required
After hooks β functional components can do everything
β *Common hooks*
- useState β manage data
- useEffect β handle side effects
- useRef β access DOM or store values
*π Hook 1: useEffect (Side Effects)*
β *What is useEffect*
useEffect runs code when:
β Component loads
β State changes
β Props change
β Component updates
Simple meaning π Perform actions outside UI rendering.
π *Why useEffect is needed*
Used for:
- API calls
- Fetch data from server
- Timer setup
- Event listeners
- Page load logic
*βοΈ Basic Syntax*
import { useEffect } from "react";
useEffect(() => {
// code to run
}, []);
*π Run only once (on page load)*
useEffect(() => {
console.log("Component mounted");
}, []);
π Empty dependency array β runs once.
*π Run when state changes*
useEffect(() => {
console.log("Count changed");
}, [count]);
π Runs whenever count updates.
*β±οΈ Real Example β Timer*
import { useState, useEffect } from "react";
function Timer() {
const [time, setTime] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
setTime(t => t + 1);
}, 1000);
return () => clearInterval(interval);
}, []);
return <h2>{time}</h2>;
}
β Runs timer automatically
β Cleans memory using return
*π― Hook 2: useRef (Access DOM / Store Values)*
β *What is useRef*
useRef gives direct access to DOM elements. Also stores values without re-rendering.
Simple meaning π Reference to element or value.
π *Why useRef is used*
- Focus input automatically
- Access DOM elements
- Store previous value
- Avoid re-render
*βοΈ Basic Syntax*
import { useRef } from "react";
const inputRef = useRef();
*π― Example β Focus input automatically*
import { useRef } from "react";
function InputFocus() {
const inputRef = useRef();
const handleFocus = () => {
inputRef.current.focus();
};
return (
<div>
<input ref={inputRef} />
<button onClick={handleFocus}>Focus</button>
</div>
);
}
β Button click focuses input.
*βοΈ useState, useEffect, and useRef β What's the difference?*
- useState: Stores changing data that triggers re-renders.
- useEffect: Runs side effects (e.g., API calls, timers).
- useRef: Accesses DOM elements or stores values without re-rendering.
*β οΈ Common Beginner Mistakes*
- Forgetting dependency array in useEffect
- Infinite loops in useEffect
- Using useRef instead of state
- Not cleaning side effects
*π§ͺ Mini Practice Task*
- Print message when component loads using useEffect
- Create timer using useEffect
- Focus input automatically using useRef
- Store previous value using useRef
*β Mini Practice Task β Solution βοΈ*
*π¦ 1οΈβ£ Print message when component loads (useEffect)*
import { useEffect } from "react";
function App() {
useEffect(() => {
console.log("Component loaded successfully");
}, []); // runs only once
return <h2>Check console</h2>;
}
export default App;
β Runs once when page loads.
*β±οΈ 2οΈβ£ Create timer using useEffect*
import { useState, useEffect } from "react";
function Timer() {
const [time, setTime] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
setTime((t) => t + 1);
}, 1000);
return () => clearInterval(interval); // cleanup
}, []);
return <h2>Time: {time}</h2>;
}
export default Timer;
β Increases every second
β Clears interval to prevent memory leak
*π― 3οΈβ£ Focus input automatically using useRef*
import { useRef } from "react";
function FocusInput() {
const inputRef = useRef();
const handleFocus = () => {
inputRef.current.focus();
};
return (
<div>
<input ref={inputRef} placeholder="Enter text" />
<button onClick={handleFocus}>Focus Input</button>
</div>
);
}
export default FocusInput;
*βοΈ React Hooks (useEffect & useRef)*
π Now you learn how React handles side effects and DOM access. These hooks are heavily used in real projects and interviews.
*π§ What are React Hooks*
Hooks let you use React features inside functional components.
Before hooks β class components required
After hooks β functional components can do everything
β *Common hooks*
- useState β manage data
- useEffect β handle side effects
- useRef β access DOM or store values
*π Hook 1: useEffect (Side Effects)*
β *What is useEffect*
useEffect runs code when:
β Component loads
β State changes
β Props change
β Component updates
Simple meaning π Perform actions outside UI rendering.
π *Why useEffect is needed*
Used for:
- API calls
- Fetch data from server
- Timer setup
- Event listeners
- Page load logic
*βοΈ Basic Syntax*
import { useEffect } from "react";
useEffect(() => {
// code to run
}, []);
*π Run only once (on page load)*
useEffect(() => {
console.log("Component mounted");
}, []);
π Empty dependency array β runs once.
*π Run when state changes*
useEffect(() => {
console.log("Count changed");
}, [count]);
π Runs whenever count updates.
*β±οΈ Real Example β Timer*
import { useState, useEffect } from "react";
function Timer() {
const [time, setTime] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
setTime(t => t + 1);
}, 1000);
return () => clearInterval(interval);
}, []);
return <h2>{time}</h2>;
}
β Runs timer automatically
β Cleans memory using return
*π― Hook 2: useRef (Access DOM / Store Values)*
β *What is useRef*
useRef gives direct access to DOM elements. Also stores values without re-rendering.
Simple meaning π Reference to element or value.
π *Why useRef is used*
- Focus input automatically
- Access DOM elements
- Store previous value
- Avoid re-render
*βοΈ Basic Syntax*
import { useRef } from "react";
const inputRef = useRef();
*π― Example β Focus input automatically*
import { useRef } from "react";
function InputFocus() {
const inputRef = useRef();
const handleFocus = () => {
inputRef.current.focus();
};
return (
<div>
<input ref={inputRef} />
<button onClick={handleFocus}>Focus</button>
</div>
);
}
β Button click focuses input.
*βοΈ useState, useEffect, and useRef β What's the difference?*
- useState: Stores changing data that triggers re-renders.
- useEffect: Runs side effects (e.g., API calls, timers).
- useRef: Accesses DOM elements or stores values without re-rendering.
*β οΈ Common Beginner Mistakes*
- Forgetting dependency array in useEffect
- Infinite loops in useEffect
- Using useRef instead of state
- Not cleaning side effects
*π§ͺ Mini Practice Task*
- Print message when component loads using useEffect
- Create timer using useEffect
- Focus input automatically using useRef
- Store previous value using useRef
*β Mini Practice Task β Solution βοΈ*
*π¦ 1οΈβ£ Print message when component loads (useEffect)*
import { useEffect } from "react";
function App() {
useEffect(() => {
console.log("Component loaded successfully");
}, []); // runs only once
return <h2>Check console</h2>;
}
export default App;
β Runs once when page loads.
*β±οΈ 2οΈβ£ Create timer using useEffect*
import { useState, useEffect } from "react";
function Timer() {
const [time, setTime] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
setTime((t) => t + 1);
}, 1000);
return () => clearInterval(interval); // cleanup
}, []);
return <h2>Time: {time}</h2>;
}
export default Timer;
β Increases every second
β Clears interval to prevent memory leak
*π― 3οΈβ£ Focus input automatically using useRef*
import { useRef } from "react";
function FocusInput() {
const inputRef = useRef();
const handleFocus = () => {
inputRef.current.focus();
};
return (
<div>
<input ref={inputRef} placeholder="Enter text" />
<button onClick={handleFocus}>Focus Input</button>
</div>
);
}
export default FocusInput;
β
Click button β input gets focus.
*π 4οΈβ£ Store previous value using useRef*
import { useState, useEffect, useRef } from "react";
function PreviousValue() {
const [count, setCount] = useState(0);
const prevCount = useRef();
useEffect(() => {
prevCount.current = count;
});
return (
<div>
<h2>Current: {count}</h2>
<h2>Previous: {prevCount.current}</h2>
<button onClick={() => setCount(count + 1)}> Increase </button>
</div>
);
}
export default PreviousValue;
β Stores previous state without re-rendering.
*π§ What You Learned*
β Run code on component load
β Handle side effects safely
β Access DOM using useRef
β Store values without re-render
β Clean up side effects
β‘οΈ *Double Tap β₯οΈ For More*
*π 4οΈβ£ Store previous value using useRef*
import { useState, useEffect, useRef } from "react";
function PreviousValue() {
const [count, setCount] = useState(0);
const prevCount = useRef();
useEffect(() => {
prevCount.current = count;
});
return (
<div>
<h2>Current: {count}</h2>
<h2>Previous: {prevCount.current}</h2>
<button onClick={() => setCount(count + 1)}> Increase </button>
</div>
);
}
export default PreviousValue;
β Stores previous state without re-rendering.
*π§ What You Learned*
β Run code on component load
β Handle side effects safely
β Access DOM using useRef
β Store values without re-render
β Clean up side effects
β‘οΈ *Double Tap β₯οΈ For More*
β€1
DSA #27 - Core Data Structures | Next Greater Element using Stack - Brute Force vs Optimized
https://youtu.be/K9yheNOvRus
https://youtu.be/K9yheNOvRus
YouTube
DSA #27 - Core Data Structures | Next Greater Element using Stack - Brute Force vs Optimized
DSA Phase-3 Core Data Structures tutorial focusing on the Next Greater Element problem using Stack.
In this video you will learn what Next Greater Element is, compare brute force vs optimized approaches, and understand the Monotonic Stack concept.
We willβ¦
In this video you will learn what Next Greater Element is, compare brute force vs optimized approaches, and understand the Monotonic Stack concept.
We willβ¦
β€1