π React Components (Functional & Class Basics) β Complete Theory Guide
1. πΉ Introduction
β What are Components?
In React, components are the fundamental building blocks of a UI. They are reusable, independent pieces of code that return UI elements. There are two main types:- Functional Components (modern, preferred)
- Class Components (legacy but still important for understanding React evolution)
π‘ Why Components are Important
- Enable modular architecture
- Promote code reuse
- Improve maintainability
- Allow separation of concerns
- Help manage UI logic efficiently
π When & Why We Use Components
Use components when:- UI can be broken into smaller parts (e.g., Navbar, Card, Button)
- You want reusable UI patterns
- You need to isolate logic (state, effects)
<Header /><Sidebar /><ProductCard />
2. βοΈ Concepts / Internal Workings
πΉ 2.1 Functional Components
A functional component is simply a JavaScript function that returns JSX.Key Characteristics:
- Stateless (initially), but now use Hooks
- Lightweight and faster
- Easier to read and test
πΉ 2.2 Class Components
A class component is a JavaScript class that extendsReact.Component.
Key Characteristics:
- Uses lifecycle methods
- Has
thisbinding - Manages state via
this.state
πΉ 2.3 JSX β React Elements β Virtual DOM
Flow:
- JSX is written
- Transpiled to
React.createElement - Creates Virtual DOM
- React compares (Diffing)
- Updates real DOM (Reconciliation)
πΉ 2.4 Props (Input to Components)
Props = Read-only data passed from parent to child.πΉ 2.5 State (Internal Data)
State is mutable data inside a component.Functional (Hooks):
Class:
πΉ 2.6 Lifecycle (Class Components)
Important lifecycle methods:| Phase | Method |
|---|---|
| Mounting | componentDidMount |
| Updating | componentDidUpdate |
| Unmounting | componentWillUnmount |
πΉ 2.7 Functional Alternative to Lifecycle (Hooks)
useEffect()replaces lifecycle methods
πΉ 2.8 Component Tree & Re-rendering
- React builds a component tree
-
Re-renders happen when:
- Props change
- State changes
πΉ 2.9 Relationship with Other React Features
| Feature | Relationship |
|---|---|
| Hooks | Used in functional components |
| Context API | Share data across components |
| Redux | External state management |
| React Router | Component-based navigation |
3. π§ͺ Syntax & Examples
πΉ 3.1 Basic Functional Component
πΉ 3.2 Arrow Function Component
πΉ 3.3 Component with Props
πΉ 3.4 Nested Components
πΉ 3.5 Conditional Rendering
πΉ 3.6 List Rendering
πΉ 3.7 Class Component Example
πΉ 3.8 Controlled Component
4. β οΈ Edge Cases / Common Mistakes
β 4.1 Mutating State Directly
β 4.2 Missing key in Lists
β 4.3 Infinite Re-renders
β 4.4 this Binding Issues (Class)
β 4.5 Incorrect useEffect Dependencies
β 4.6 Re-rendering All Components
- Happens when parent state updates unnecessarily
- Use
React.memo - Split components
5. β Best Practices
πΉ 5.1 Prefer Functional Components
- Cleaner
- Hooks-based
- Future-proof
πΉ 5.2 Keep Components Small & Focused
- One responsibility per component
πΉ 5.3 Use Destructuring
πΉ 5.4 Use Proper Naming
-
PascalCase for components:
UserCardNavbar
πΉ 5.5 Avoid Inline Functions (Performance)
πΉ 5.6 Use Memoization
πΉ 5.7 Avoid Prop Drilling
π Use:- Context API
- State management tools
πΉ 5.8 Use Keys Properly
- Never use index unless necessary
- Use unique IDs
πΉ 5.9 Optimize Re-renders
useMemouseCallback
πΉ 5.10 Folder Structure
π Summary
- Components are the core of React architecture
- Functional components + Hooks are the modern standard
- Class components are important for legacy understanding
- Proper structure and optimization lead to scalable apps
Below is a senior-level conceptual interview set on React Components (Functional & Class Basics) β focused on depth, internal behavior, trade-offs, and real-world thinking.
π§ Advanced React Components β Interview Questions & Answers
1. Why did React shift from Class Components to Functional Components with Hooks?
β Strong Answer
The shift was driven by simplicity, composability, and better logic reuse.π Key Reasons
-
Separation of Concerns
- Class components split logic across lifecycle methods
- Hooks allow grouping related logic together
-
Avoid
thisComplexity- Class components require binding
- Functional components eliminate
this
-
Better Code Reuse
- Hooks replace HOCs and render props
- Less Boilerplate
π‘ Example Comparison
Class (fragmented logic):βοΈ Trade-off
- Hooks introduce dependency array complexity
- Requires understanding of closures
2. How does React internally treat Functional vs Class components?
β Strong Answer
Internally, both are treated as units that produce React elements, but:- Class Components β instantiated with
new - Functional Components β invoked as plain functions
π Internal Differences
| Aspect | Functional | Class |
|---|---|---|
| Execution | Function call | Class instance |
| State storage | Hook list (linked to fiber) | Instance (this.state) |
| Lifecycle | useEffect hooks | Lifecycle methods |
π§ Fiber Insight
React stores hooks in a linked list inside Fiber nodes, maintaining order across renders.3. Why must Hooks be called unconditionally and in the same order?
β Strong Answer
React relies on call order to map hooks to internal state slots.π Internal Reason
React does NOT track hooks by name β it tracks by position.π‘ Why it breaks?
- On next render, hook order changes
- React mismatches state
4. What actually triggers a component re-render?
β Strong Answer
A component re-renders when:- State changes
- Props change
- Parent re-renders
- Context changes
π Important Insight
React does NOT deeply compare values β it relies on reference equality.βοΈ Optimization
React.memouseMemouseCallback
5. Why is direct state mutation a critical issue?
β Strong Answer
React relies on immutability for change detection.π Problem
- Reference is unchanged
β Correct
6. How does React reconcile component trees?
β Strong Answer
React uses a diffing algorithm (Reconciliation):- Compare old vs new Virtual DOM
- Identify minimal changes
- Update real DOM efficiently
π Key Assumptions
- Elements of different types β replace
- Keys help track identity
7. Why are keys critical in list rendering?
β Strong Answer
Keys help React preserve component identity across renders.π Problem Without Keys
- Causes incorrect DOM reuse
- Leads to bugs (especially in forms)
π‘ Real Issue
- Input values shifting unexpectedly
8. Explain the difference between controlled and uncontrolled components.
β Strong Answer
| Type | Controlled | Uncontrolled |
|---|---|---|
| Data Source | React state | DOM |
| Control | Full control | Less control |
π‘ Example
βοΈ Trade-off
- Controlled β predictable but verbose
- Uncontrolled β simpler but less flexible
9. What are the hidden pitfalls of useEffect?
β Strong Answer
- Stale closures
- Missing dependencies
- Infinite loops
π‘ Example
β Fix
10. Why do functions inside components cause performance issues?
β Strong Answer
Functions are recreated on every render β new reference β triggers child re-renders.β Fix
11. How does React.memo work internally?
β Strong Answer
- Performs shallow comparison of props
- Skips re-render if props unchanged
β οΈ Limitation
- Always re-renders due to new reference
12. When would you still use Class Components today?
β Strong Answer
- Legacy codebases
- Error boundaries (before hooks alternative)
βοΈ Trade-off
- More verbose
- Less composable
13. Explain lifting state up and its trade-offs.
β Strong Answer
Moving shared state to the closest common ancestor.π‘ Problem
- Leads to prop drilling
β Alternative
- Context API
- State libraries
14. What is prop drilling and how do you avoid it?
β Strong Answer
Passing props through multiple layers unnecessarily.β Solutions
- Context API
- Redux / Zustand
15. How do closures affect React components?
β Strong Answer
Closures can capture stale state values.β Fix
16. Why is component composition preferred over inheritance in React?
β Strong Answer
React promotes composition for flexibility.π‘ Example
βοΈ Why not inheritance?
- Tight coupling
- Less reusable
17. How does React batch state updates?
β Strong Answer
React groups multiple updates into a single render for performance.π React 18+
- Automatic batching even in async code
18. What are render phases vs commit phases?
β Strong Answer
| Phase | Description |
|---|---|
| Render | Calculate changes |
| Commit | Apply to DOM |
π Insight
- Render phase can be interrupted
- Commit phase is synchronous
19. Why can excessive component re-rendering become a bottleneck?
β Strong Answer
Because React:- Re-executes component functions
- Recalculates Virtual DOM
π Real-world Impact
- Slow UI in large trees
β Fix
- Memoization
- Splitting components
20. How do you decide component boundaries in a real application?
β Strong Answer
Based on:- Reusability
- Separation of concerns
- Performance isolation
π‘ Bad Design
- One giant component
π‘ Good Design
- Small, focused, composable components
π Final Takeaway
Senior-level understanding of components is about:- Thinking in render cycles
- Understanding React internals (Fiber, reconciliation)
- Managing performance trade-offs
- Designing scalable component architecture
Below is a senior-level MCQ set (18 questions) on React Components (Functional & Class Basics). Each question targets deep understanding, edge cases, and real-world behavior.
π§ Advanced React Components β MCQs
1. What happens when you update state with the same value?
Options:
A. Component always re-renders B. Component never re-renders C. React may skip re-render using Object.is comparison D. React throws an errorβ Correct Answer: C
π‘ Explanation:
React uses Object.is comparison. If the value is identical, React bails out of re-render.β Why others are wrong:
- A: Incorrect β React optimizes unnecessary renders
- B: Not always true (edge cases like forced updates)
- D: No error occurs
2. What is the output?
Options:
A. Logs 0 B. Logs 1 C. Logs 0 then 1 D. Infinite loopβ Correct Answer: C
π‘ Explanation:
- Initial render β logs
0 - Effect runs after render β updates state β re-render β logs
1
β Others:
- A/B: Ignore lifecycle timing
- D: No dependency loop
3. Why is this problematic?
Options:
A. It runs too many times B. It may use stale variables C. It blocks rendering D. It causes memory leaks alwaysβ Correct Answer: B
π‘ Explanation:
The empty dependency array can cause stale closure issues iffetchData depends on changing values.
4. What happens here?
Options:
A. Two re-renders B. One re-render C. No re-render D. Errorβ Correct Answer: B
π‘ Explanation:
Same reference β React batches updates β single re-render.5. What is the issue with index as key?
Options:
A. Performance issue only B. Causes incorrect DOM reuse C. Causes syntax error D. Prevents renderingβ Correct Answer: B
π‘ Explanation:
Index keys break component identity, causing UI bugs during reorder.6. What happens when parent re-renders?
Options:
A. Only changed children render B. All children render by default C. React skips all children D. Only stateful children renderβ Correct Answer: B
π‘ Explanation:
React re-runs all child components unless optimized.7. What is wrong here?
Options:
A. Nothing B. Causes memory leak C. Breaks hook order D. Slows performanceβ Correct Answer: C
π‘ Explanation:
Hooks must be called in the same order every render.8. Why does this re-render child?
Options:
A. Because object is mutable B. New reference each render C. React deep compares D. Child forces updateβ Correct Answer: B
9. What happens in this case?
Options:
A. +2 increment B. +1 increment C. Infinite loop D. No changeβ Correct Answer: B
π‘ Explanation:
Both updates use same stale value.10. Correct fix?
Options:
A.setCount(count + 2)
B. setCount(prev => prev + 1) twice
C. setCount(() => count + 1)
D. UseEffect
β Correct Answer: B
11. Why is this inefficient?
Options:
A. Syntax error B. Recreates function every render C. Blocks UI D. Causes memory leakβ Correct Answer: B
12. What does React.memo NOT handle well?
Options:
A. Primitive props B. Stable references C. Inline objects/functions D. Static componentsβ Correct Answer: C
13. What happens here?
Options:
A. No re-render B. Re-render occurs C. Error D. Infinite loopβ Correct Answer: B
π‘ Explanation:
New object reference β triggers render.14. Why is this unsafe?
Options:
A. Syntax issue B. Mutation breaks React detection C. Causes crash D. Async issueβ Correct Answer: B
15. What is true about class vs functional?
Options:
A. Class is faster B. Functional supports hooks C. Class supports hooks D. Functional cannot manage stateβ Correct Answer: B
16. What happens during reconciliation?
Options:
A. Full DOM replacement B. Minimal updates via diffing C. No updates D. Random updatesβ Correct Answer: B
17. What is the problem here?
Options:
A. Runs once B. Infinite loop C. No update D. Errorβ Correct Answer: B
18. Why prefer composition over inheritance?
Options:
A. Less code B. More flexibility and reuse C. Required by React D. Better performance onlyβ Correct Answer: B
π Final Insight
These questions test:- Render cycle understanding
- Hook behavior & pitfalls
- Reconciliation & identity
- Performance reasoning
- Real-world debugging mindset
Below is a senior-level coding problem set (18 problems) focused on React Components (Functional & Class Basics). Each problem simulates real-world scenarios, emphasizes thinking, and includes edge cases + reasoning.
π§ Advanced React Component Coding Problems
1. π Smart Counter with Sync Issues
π§© Problem
Build a counter that:- Increments correctly even with rapid clicks
- Logs correct value after async delay
β οΈ Constraints
- Avoid stale state
- Must handle async updates
β Expected Behavior
- Clicking 3 times β count = 3
- Console logs correct count
β οΈ Edge Cases
- Rapid clicks
- Async delays
π‘ Solution
π§ Fix Explanation
Use ref to avoid stale closure:2. π Prevent Unnecessary Re-renders
π§© Problem
Optimize a child component so it doesnβt re-render unnecessarily.Constraints
- Parent updates frequently
π‘ Solution
π§ Explanation
UseReact.memo + stable props (useMemo)
3. π§ Derived State Bug
Problem
Sync prop β state without causing inconsistency.Edge Case
- Prop updates asynchronously
β Bad
β Solution
4. π Search with Debounce
Problem
Create search input with debounce.Constraints
- Avoid excessive API calls
π‘ Solution
5. π¦ Dynamic Form Builder
Problem
Render form fields dynamically based on config.Edge Case
- Unknown field types
Solution Idea
Use component mapping:6. π Controlled vs Uncontrolled Hybrid
Problem
Input should:- Work controlled OR uncontrolled
Solution
7. π Infinite Loop Debugging
Problem
Fix infinite re-render:Solution
- Remove
datadependency - Use proper trigger
8. π§© Compound Components Pattern
Problem
Build<Tabs> system:
Solution Idea
Use Context API9. π Expensive Calculation Optimization
Problem
Prevent heavy recalculationSolution
10. π Shared State Between Siblings
Problem
Two components share stateSolution
Lift state up OR Context11. π§΅ Async Data Race Condition
Problem
Avoid outdated API results overriding new onesSolution
12. π§ Custom Hook Extraction
Problem
Extract reusable logic (e.g., window resize)Solution
13. π― Conditional Rendering Trap
Problem
Prevent component losing state when hiddenβ Bad
β Solution
Keep mounted + toggle visibility14. π List Reordering Bug
Problem
Fix UI glitch when reordering itemsSolution
Use stable unique keys (IDs)15. π§ͺ Error Boundary Implementation
Problem
Catch runtime errorsSolution (Class Only)
16. π§© Component Composition Refactor
Problem
Refactor large component into smaller onesSolution
- Split by responsibility
- Extract reusable pieces
17. β‘ Batch Updates Understanding
Problem
Explain why:Solution
React batching18. π Function Identity Bug
Problem
Child re-renders due to function propSolution
π Final Insight
These problems test:- State correctness under async conditions
- Render optimization thinking
- Component architecture design
- Real-world debugging skills
Below are 18 senior-level debugging challenges based on React Components (functional & class basics). Each mirrors real production bugs β subtle, non-trivial, and rooted in React behavior.
π Advanced React Debugging Challenges
1. π Stale Closure in Async Callback
β Buggy Code
β Whatβs Wrong
Logs stalecount value.
π€ Why It Happens
Closure captures value at render time, not latest state.β Fix
π§ Best Practice
- Use
useRefor functional updates for async logic
2. π Infinite useEffect Loop
β Code
β Problem
Infinite re-render loopπ€ Why
setDataupdatesdata- dependency triggers effect again
β Fix
π§ Best Practice
- Avoid updating dependencies inside effect
3. π¦ Re-render due to Object Props
β Code
β Problem
Child re-renders every timeπ€ Why
New object reference each renderβ Fix
π§ Best Practice
- Memoize objects/functions passed as props
4. π List Reordering Bug
β Code
β Problem
UI glitches on reorderπ€ Why
Index doesnβt preserve identityβ Fix
π§ Best Practice
- Always use stable unique keys
5. π§ Incorrect State Mutation
β Code
β Problem
Component may not re-renderπ€ Why
Reference unchanged β React doesnβt detect changeβ Fix
6. β‘ Double State Update Bug
β Code
β Problem
Only increments onceπ€ Why
Both use same stale valueβ Fix
7. π§© Missing Dependency in useEffect
β Code
β Problem
Doesnβt update whenuserId changes
π€ Why
Dependency missingβ Fix
8. π Function Prop Causing Re-render
β Code
β Problem
Child re-renders unnecessarilyπ€ Why
New function reference each renderβ Fix
9. π§ͺ useEffect Cleanup Missing
β Code
β Problem
Memory leakπ€ Why
Listener never removedβ Fix
10. π§ Derived State Desync
β Code
β Problem
State not updating with propsπ€ Why
Initial value only used onceβ Fix
11. π Conditional Hook Usage
β Code
β Problem
Hook order breaksπ€ Why
Hooks must run in same orderβ Fix
12. β οΈ Expensive Calculation Every Render
β Code
β Problem
Performance issueπ€ Why
Runs on every renderβ Fix
13. π Component Losing State
β Code
β Problem
State resets on toggleπ€ Why
Component unmountsβ Fix
14. π§΅ Async Race Condition
β Code
β Problem
Older responses overwrite newerπ€ Why
Async raceβ Fix
15. π Unnecessary Parent Re-renders
β Code
β Problem
Triggers children updatesπ€ Why
New object each renderβ Fix
16. π§ setState Async Misunderstanding
β Code
β Problem
Logs old valueπ€ Why
State updates are asyncβ Fix
17. π§© Class Component this Issue
β Code
β Problem
this undefined
π€ Why
Not boundβ Fix
18. β‘ React.memo Ineffective
β Code
β Problem
Memo not workingπ€ Why
New object every renderβ Fix
π Final Takeaways
These bugs reflect real-world issues:- Closures & async traps
- Reference equality pitfalls
- Hook rules violations
- Reconciliation misunderstandings
- Performance bottlenecks
Below is a production-grade machine coding set (18 problems) focused on React Components (Functional & Class Basics). These reflect real-world systems, FAANG-style interviews, and production architecture thinking.
ποΈ Advanced React Machine Coding Problems
1. π§ Smart Autocomplete with Caching
π Requirements
- Input field with suggestions
- Fetch suggestions via API
- Cache previous queries
- Highlight matched text
βοΈ UI Behavior
- Debounced typing (300ms)
- Loading indicator
- Keyboard navigation (β β Enter)
π State/Data Flow
query,results,cache,loading,activeIndex
β οΈ Edge Cases
- Empty input
- Rapid typing β race conditions
- Same query repeated
π Performance
- Debounce
- Memoized cache
ποΈ Architecture
SearchBoxSuggestionListuseDebounce,useCache
π§ Approach
- Capture input
- Debounce API call
- Store results in cache
- Handle keyboard navigation
2. π Virtualized Infinite List
π Requirements
- Render 10k+ items efficiently
- Infinite scroll loading
βοΈ UI Behavior
- Only visible items rendered
- Smooth scroll
π State
items,scrollTop,visibleRange
β οΈ Edge Cases
- Fast scroll jumps
- Dynamic item heights
π Performance
- Windowing (virtualization)
ποΈ Architecture
ListContainerListItem
π§ Approach
- Calculate visible indices
- Render subset only
3. π§Ύ Multi-step Form Wizard
π Requirements
- Step-based navigation
- Validation per step
- Save progress
βοΈ UI
- Next/Prev buttons
- Progress indicator
π State
- Centralized form state
β οΈ Edge Cases
- Back navigation retains data
- Validation errors
ποΈ Architecture
WizardStep- Context for state
4. π Real-time Chat UI
π Requirements
- Message list
- Auto-scroll
- Typing indicator
βοΈ Behavior
- New messages push bottom
β οΈ Edge Cases
- Scroll position preservation
- Duplicate messages
π Performance
- Virtualization for large chats
5. π§ Undo/Redo State Manager
π Requirements
- Maintain history
- Undo/redo actions
π State
past,present,future
β οΈ Edge Cases
- New action clears future
π§ Approach
- Stack-based state
6. π¦ Dynamic Dashboard Layout
π Requirements
- Drag & drop widgets
- Resizable grid
β οΈ Edge Cases
- Collision handling
ποΈ Architecture
DashboardWidget
7. π Role-based Component Rendering
π Requirements
- Render UI based on user roles
β οΈ Edge Cases
- Unauthorized access
π§ Approach
- HOC or wrapper component
8. π§Ύ Table with Sorting, Filtering, Pagination
π Requirements
- Multi-column sort
- Server/client filtering
β οΈ Edge Cases
- Large datasets
π Performance
- Memoized sorting
9. π§ Global Toast Notification System
π Requirements
- Show multiple toasts
- Auto-dismiss
ποΈ Architecture
- Context API
10. π File Explorer (Tree View)
π Requirements
- Nested folders
- Expand/collapse
β οΈ Edge Cases
- Deep nesting
11. π§© Modal Manager System
π Requirements
- Multiple modals
- Stack management
12. π Real-time Stock Dashboard
π Requirements
- Live updates
- Graph rendering
β οΈ Edge Cases
- Rapid updates
13. π§ Form Builder (Drag & Drop)
π Requirements
- Build forms dynamically
14. π Polling + Manual Refresh System
π Requirements
- Auto refresh every X sec
- Manual refresh
15. π¦ Shopping Cart with Optimistic Updates
π Requirements
- Instant UI update
- Rollback on failure
16. π§ Tabs with Lazy Loading
π Requirements
- Load content on demand
17. π Search + Highlight System
π Requirements
- Highlight matches in large text
18. π Component Visibility Tracker
π Requirements
- Detect if component in viewport
π What These Test
These problems simulate:- Real production UI systems
- State architecture decisions
- Performance bottlenecks
- Component composition skills
- Edge-case handling mindset
π If You Want Next Level
Below is a FAANG-level interview set (20 questions) on React Components (Functional & Class Basics). These emphasize decision-making, internals, trade-offs, debugging, and performance awareness.π§ Senior React Interview Questions β Components
1. When would you intentionally choose a Class Component over a Functional Component today?
π Follow-up
- How would you implement error boundaries using functional components?
- What are the trade-offs?
β Strong Answer
- Primarily for Error Boundaries (until recently functional alternatives stabilized)
- Legacy systems where refactoring cost is high
- Class lifecycle sometimes clearer for debugging complex flows
β Weak Answer
- βClass components are fasterβ π Incorrect β no inherent performance advantage
2. Explain how React keeps track of state in functional components internally.
π Follow-up
- Why does hook order matter?
β Strong Answer
- React stores hooks in a linked list tied to Fiber nodes
- State is mapped by call order, not variable names
β Weak Answer
- βReact tracks state by variable nameβ π Completely incorrect mental model
3. You see unnecessary re-renders in a deep component tree. How do you debug it?
π Follow-up
- What tools and techniques do you use?
β Strong Answer
- Use React DevTools Profiler
- Identify prop changes (reference vs value)
- Check parent re-renders
- Apply memoization strategically
β Weak Answer
- βJust add React.memo everywhereβ π Blind optimization β can worsen performance
4. Why does this cause a bug?
π Follow-up
- How does batching affect this?
β Strong Answer
- Both updates use stale value
- React batches updates β final state incorrect
β Weak Answer
- βBecause setState is asyncβ π Incomplete explanation
5. How would you design a reusable component system for a large application?
π Follow-up
- How do you prevent tight coupling?
β Strong Answer
- Use composition over inheritance
- Isolate concerns
- Use controlled props + slots pattern
β Weak Answer
- βJust break into smaller componentsβ π Lacks architectural thinking
6. Explain a real-world bug caused by using index as key.
π Follow-up
- When is it acceptable?
β Strong Answer
- Reordering lists β incorrect DOM reuse
- Example: form inputs shifting values
β Weak Answer
- βItβs only a performance issueβ π Itβs a correctness issue
7. How do closures impact React components?
π Follow-up
- Give a real bug example
β Strong Answer
- Closures capture stale values
- Common in async callbacks, effects
β Weak Answer
- βClosures donβt matter in Reactβ π Fundamental misunderstanding
8. What are the trade-offs of lifting state up?
π Follow-up
- When does it become a problem?
β Strong Answer
- Enables shared state
- But leads to prop drilling + unnecessary renders
β Weak Answer
- βItβs always best practiceβ π Not scalable in large apps
9. Why is React.memo sometimes ineffective?
π Follow-up
- How do you fix it?
β Strong Answer
- Fails with unstable references (objects/functions)
β Weak Answer
- βBecause memo is buggyβ π Misunderstanding of reference equality
10. Explain reconciliation and its assumptions.
π Follow-up
- How do keys affect it?
β Strong Answer
- React uses O(n) diffing heuristic
- Assumes stable structure + keys
β Weak Answer
- βReact compares everything deeplyβ π Incorrect
11. You have a component that fetches data. It sometimes shows outdated results. Why?
π Follow-up
- How do you fix it?
β Strong Answer
- Race condition
- Older request resolves after newer one
β Weak Answer
- βAPI is slowβ π Avoids root cause
12. How would you prevent unnecessary re-renders in a form-heavy UI?
π Follow-up
- Controlled vs uncontrolled trade-offs?
β Strong Answer
- Split components
- Use local state
- Avoid global re-renders
β Weak Answer
- βUse Reduxβ π Doesnβt solve rendering issue
13. Why are hooks restricted to top-level calls?
π Follow-up
- What breaks if violated?
β Strong Answer
- Hook order consistency required for state mapping
β Weak Answer
- βJust a React ruleβ π No understanding of internals
14. How do you handle expensive computations in components?
π Follow-up
- When is useMemo harmful?
β Strong Answer
- Use
useMemowhen needed - Avoid overuse (adds overhead)
β Weak Answer
- βAlways use useMemoβ π Premature optimization
15. Describe a scenario where a component should NOT re-render but does.
π Follow-up
- How do you fix it?
β Strong Answer
- Caused by new prop references
- Fix via memoization or restructuring
16. What happens during render vs commit phases?
π Follow-up
- Why is this important?
β Strong Answer
- Render = calculate changes (can be interrupted)
- Commit = apply changes (synchronous)
17. How do you design components for scalability?
π Follow-up
- What anti-patterns do you avoid?
β Strong Answer
- Small, composable components
- Avoid monolith components
18. How would you debug a component that resets its state unexpectedly?
π Follow-up
- What React concept is involved?
β Strong Answer
- Likely unmount/remount issue
- Caused by conditional rendering or key change
19. Explain controlled vs uncontrolled components in a large system.
π Follow-up
- When do you mix both?
β Strong Answer
- Controlled = predictable
- Uncontrolled = performance-friendly
20. How do you decide component boundaries in a performance-critical app?
π Follow-up
- What trade-offs do you consider?
β Strong Answer
-
Balance between:
- Reusability
- Render isolation
- Complexity
π Final Evaluation Criteria (What Interviewers Look For)
A strong candidate demonstrates:- π§ Mental model of React internals
- βοΈ Trade-off awareness
- π Debugging mindset
- π Performance reasoning
- ποΈ Component architecture thinking