Lessons available in both languages
MERN Stack · Interview Prep

React interview questions & answers

174+ real React interview questions with model answers, plus free lessons to learn the concepts. Prepare in English & Hinglish, then practise with an AI mock interview.

17 topics · 174+ questions

Hirenix kaise padhata hai

Ek chapter. 90 minute.
Interview ke liye taiyaar.

Har concept ek real-world problem se — jaisa production code mein aata hai, waisa. Ratna nahi padta, samajh aa jaata hai. Har question ka model answer diya hai: interviewer ko exactly kya bolna hai, aur kyun. Phir usi chapter ka AI mock interview.

  • 📖Concept, 5 min meinJargon nahi — seedhi baat
  • 🛠️Real-world problemJaisa production code mein aata hai
  • 💬Model answerInterview mein kya bolna hai
  • 🧠FlashcardsRevision 10 min mein
  • 🤖AI mock interviewFollow-up bhi poochta hai
  • 📊Weak topicsKahan phans rahe ho, pata chale
Ye chapter shuru karo — free🌐 English🇮🇳 Hinglish
A student learning an interview concept on Hirenix at home
Video playlistsyllabus ke hisaab se18h+
Hirenix chapterinterview ke hisaab se90 min

Farq content ka nahi, filter ka hai — sirf wahi jo production mein actually use hota hai aur interview mein actually poocha jaata hai. Kitaabi topics jo industry mein kahin nahi chalte, wo yahan nahi milenge.

Lessons available in both languages

What you’ll learn

  • React kya hai?
  • JSX kya hota hai?
  • Components & PropsFree account
  • State & useStateFree account
  • useEffect & lifecycleFree account
  • Conditional renderingFree account
  • Lists & keysFree account
  • Forms & inputsFree account
  • Context APIFree account
  • Custom hooksFree account
  • Redux basicsFree account
  • Performance & memoFree account
  • React RouterFree account
  • Interview recapFree account
  • Project 1: Counter
  • Project 2: Signup form + validationFree account
  • Project 3: Todo app (poora build)Free account

React kya hai?

Socho tum ek Lego set se ghar bana rahe ho. Poora ghar ek saath nahi banate — chhote-chhote blocks jodte ho: darwaza block, khidki block, deewar block. Ek block kharab ho to sirf usko badalte ho, poora ghar nahi todte.

React bhi bilkul aisa hi hai. Website ko chhote-chhote "components" (blocks) me todta hai — Navbar, Button, Card. Har component alag, reusable, aur agar ek badalna ho to sirf wahi update hota hai — poora page reload nahi hota.

🌍 Real-world example: Instagram feed dekho — ek post like karo, sirf us post ka dil laal hota hai, poori feed refresh nahi hoti. Yeh React ka kamaal hai: sirf jo badla, wahi dobara draw hota hai (isko "re-render" kehte hain).

Standard definition (interview me bolo): React is an open-source JavaScript library developed by Meta for building user interfaces using reusable, component-based architecture with a virtual DOM for efficient rendering.

function Welcome() {
  return <h1>Namaste, Hirenix!</h1>;
}
// Ise screen par use karo:
<Welcome />

JSX kya hota hai?

JSX ko aise samjho jaise WhatsApp message me text ke beech emoji mix karna — emoji plain text nahi hote, par tumhara phone samajh ke dikha deta hai. JSX bhi HTML-jaise tags ko seedha JavaScript ke andar mix karta hai taaki UI likhna natural lage.

Par browser sirf plain JavaScript samajhta hai, JSX nahi. Isliye Babel naam ka tool chupchaap tumhare JSX ko plain React.createElement(...) calls me translate kar deta hai, browser ke dekhne se pehle.

💡 Babel kya hai? Babel ek free tool hai jise compiler kehte hain — yeh us code ko jo browser padh nahi sakta (jaise JSX, ya JavaScript ke naye features) purani, plain JavaScript me badal deta hai jo har browser samajhta hai. Yeh tumhare project build hote waqt apne-aap chalta hai, background me kaam karte translator ki tarah.

🌍 Real-world example: Tum JS file me <h1>Hello</h1> likhte ho. Babel use React.createElement('h1', null, 'Hello') me badal deta hai, jo ek plain JS object banata hai jise React render kar sakta hai. Tumhe aasaan HTML-jaisa code milta hai; React ko uske objects mil jaate hain.

Standard definition: JSX (JavaScript XML) JavaScript ka ek syntax extension hai jo tumhe JavaScript ke andar HTML-jaisa markup likhne deta hai; ise (Babel dwara) React.createElement calls me compile kiya jaata hai jo React elements return karte hain.

const name = "Hirenix";
const heading = <h1>Hello, {name}!</h1>;
// Babel turns the JSX into:
// React.createElement('h1', null, 'Hello, ', name, '!')

Project 1: Counter

Kya bana rahe hain: Ek Counter app — screen pe ek number, aur +, , Reset buttons. Chhota hai, par ye React ka sabse important loop sikhata hai: event → setState → React tumhare component ko dobara chalata hai → re-render → UI update. Ye pakka aa gaya, to baaki sab bas isi ke variations hain.

React concepts jo ye sikhata hai: useState, event handlers (onClick), setter function, functional updates (setCount(c => c + 1)) vs value updates (setCount(count + 1)), aur golden rule — tum STATE badalte ho, DOM nahi.


Step 0 — Mental model (pehle ye padho, 30 second)

Normal HTML/JavaScript mein agar tumhe screen pe number badalna ho, to element pakad ke likhte: document.getElementById('x').innerText = 5. Tum khud DOM ko haath lagate ho.

React ulta chalta hai. Tum DOM ko kabhi haath nahi lagate. Uski jagah tum ek data rakhte ho jise state kehte hain, aur React ko batate ho ki is state ke liye screen kaisi dikhni chahiye. Jab state badalti hai, React khud screen dobara bana deta hai. Tumhara sirf ek kaam: jab kuch ho, state update kar do. Drawing React karega.

💡 State = ek value jise React watch karta hai. Jab wo badalti hai, React us component ko dobara draw karta hai.

Ye picture dimaag mein rakho. Ab banate hain.


Step 1 — Bas ek number dikhao

import { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>Count: {count}</p>
    </div>
  );
}

export default Counter;

Ho ye raha hai: useState(0) ek state banata hai aur usko 0 se shuru karta hai. Ye tumhe ek array wapas deta hai jismein exactly do cheezein hoti hain, aur hum unhe const [count, setCount] = ... se unpack karte hain:

  • countcurrent value (abhi 0). Ye read-only snapshot hai.
  • setCountsetter, us value ko badalne ka EK-hi sahi tarika.

JSX mein {count} current value ko page mein daal deta hai, to screen pe Count: 0 dikhta hai. Dhyaan do: humne DOM ko haath nahi lagaya, bas describe kiya ki current state ke liye kya dikhana hai. Yahi poora idea hai.

💡 Sirf let count = 0 kyun nahi? Kyunki normal variable badalne pe React ko kuch nahi batata — screen kabhi update nahi hoti. useState React ko ek aisi value deta hai jise wo watch karta hai.


Step 2 — + button (ye sabse bada hai)

import { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>+</button>
    </div>
  );
}

export default Counter;

Ho ye raha hai: Ye core loop hai — dheere se trace karo, kyunki har React app ka har button bilkul isi tarah chalta hai:

  1. Tum + button click karte ho.
  2. Button ka onClick fire hota hai, jo arrow function () => setCount(count + 1) chalata hai.
  3. count abhi 0 hai, to ye setCount(0 + 1)setCount(1) call karta hai.
  4. Setter React ko batata hai: "bhai, is state ki nayi value 1 hai."
  5. React jawab mein poore Counter function ko upar se dobara chalata hai.
  6. Is naye run mein useState updated value deta hai — ab count hai 1.
  7. JSX Count: 1 banata hai, React usse screen se compare karke sirf badla hua hissa re-render karta hai.
  8. Tumhe Count: 1 dikhta hai.

💡 onClick React ka click handler lagane ka tarika hai. Hum usmein ek function dete hain (() => ...), call nahi. Agar tum onClick={setCount(count + 1)} likhte (bina arrow), to wo render ke waqt hi turant chal jata, click pe nahi — ek classic beginner bug.

Button ne screen ke number ko kabhi haath nahi lagaya. Usne state badli. State badalna hi hai jo React ko dobara draw karne pe majboor karta hai. Zor se bolo: button state badalta hai, DOM nahi.


Step 3 — − button (decrement)

<p>Count: {count}</p>
<button onClick={() => setCount(count - 1)}>-</button>
<button onClick={() => setCount(count + 1)}>+</button>

Ho ye raha hai: Bilkul wahi loop, ulta math. click → onClick setCount(count - 1) chalata hai. Agar count 3 hai, to ye setCount(2). Setter React ko batata hai state badli → React Counter dobara chalata hai → ab count 2 hai → screen Count: 2 dikhata hai. Do buttons, ek shared state — dono bas setter ko alag number ke saath call karte hain.


Step 4 — Reset button

<button onClick={() => setCount(0)}>Reset</button>

Ho ye raha hai: Reset sabse simple hai — ise parwah nahi ki count abhi kya hai. Ye setCount(0) call karta hai, state ko seedha 0 pe set kar deta hai. Setter → React Counter dobara chalata hai → count 0 hai → screen Count: 0 dikhata hai. Phir wahi loop. Loop ek baar samajh aa gaya, to koi bhi button add kar sakte ho.


Step 5 — Functional update: setCount(c => c + 1)

+ handler ko value update se functional update mein badlo:

<button onClick={() => setCount(c => c + 1)}>+</button>

Ho ye raha hai: Dono version 1 add karte hain, to fark kya? Fark hai +1 kahaan se shuru hota hai.

  • setCount(count + 1)value update. Ye count ko waisa use karta hai jaisa is handler ke bante waqt capture hua tha. Wo snapshot purana (stale) ho sakta hai.
  • setCount(c => c + 1)functional update. Tum ek function pass karte ho. React usse call karke latest value c mein deta hai, aur jo tum return karte ho wahi nayi state banti hai. Koi stale snapshot nahi.

Kyun important hai — socho ek "+3" button jo ek click mein teen updates lagata hai:

// GALAT: teeno wahi stale count (maano 0) padhte hain → har baar 0+1 → 1 pe rukta hai, 3 pe nahi
<button onClick={() => { setCount(count + 1); setCount(count + 1); setCount(count + 1); }}>+3</button>

// SAHI: har ek ko latest value milti hai → 0→1→2→3
<button onClick={() => { setCount(c => c + 1); setCount(c => c + 1); setCount(c => c + 1); }}>+3</button>

💡 Thumb rule: agar nayi state purani state pe depend karti hai, to function form use karo setCount(c => c + 1). Ye hamesha safe hai.


Step 6 — Chhota twist: 0 ke neeche nahi ja sakta

Ek rule add karte hain: counter kabhi negative number na dikhaye. Ye dikhata hai ki conditional logic setter ke andar kaise rehta hai.

<button onClick={() => setCount(c => (c > 0 ? c - 1 : 0))}>-</button>

Ho ye raha hai: Click pe functional update latest c ke saath chalta hai. Ternary c > 0 ? c - 1 : 0 kehta hai: agar zero se upar hain to ek neeche jao; warna 0 pe raho. To count = 0 pe dabane pe 0 return hota hai — React dobara chalta hai, count abhi bhi 0, screen hilti nahi. Floor is baat se lag raha hai ki tum state mein kya value daalte ho, kisi cheez ko disable karke nahi. (Button ko disable bhi kar sakte ho — practice challenges mein dikhaya hai.)

💡 Ternary condition ? a : b = ek line ka if/else. Padho "agar condition to a, warna b."


🔎 Poora flow (wiring ka recap)

Ye raha finished app, click-by-click:

  1. Page loadCounter() chalta hai → useState(0) count = 0 set karta hai → JSX Count: 0 dikhata hai.
  2. + clickonClick setCount(c => c + 1) chalata hai → setter React ko batata hai "state badli" → React Counter dobara chalata hai → ab count 1re-render → screen Count: 1.
  3. − clickonClick setCount(c => (c > 0 ? c - 1 : 0)) chalata hai → latest c se nayi value bani → setter → dobara run → re-render → number neeche jata hai (0 ke neeche kabhi nahi).
  4. Reset clickonClick setCount(0) chalata hai → setter → dobara run → re-render → Count: 0 dikhata hai.

Har ek button wahi chaar beats follow karta hai: event → setState → React component dobara chalata hai → UI update. Tumne ek bhi line nahi likhi jo screen ke number ko seedha haath lagati ho — tumne bas state badli.


✅ Jo tumne abhi seekha

  • useState — ek state value aur uska setter kaise banate hain: const [count, setCount] = useState(0).
  • Event handlersonClick={() => ...} ek function attach karta hai jo click pe chalta hai (function pass karo, call nahi).
  • Setter re-render chalata haisetCount(...) call karna hi hai jo React ko component dobara chalane aur UI update karne ko kehta hai.
  • Tum STATE badalte ho, DOM nahi — button state badalta hai; state badalna hi screen ko dobara draw karta hai.
  • Functional updatessetCount(c => c + 1) latest value use karta hai aur safe hai jab nayi state purani pe depend kare; setCount(count + 1) stale snapshot use kar sakta hai.
  • Setter ke andar conditional logic — ternary se state ko rules ke andar rakhna (kabhi 0 ke neeche nahi).
  • Universal loopevent → setState → dobara run → re-render. Har interactive React app isi pe bana hai.
import { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);

  return (
    <div>
      <h2>Counter</h2>
      <p>Count: {count}</p>
      <button onClick={() => setCount(c => (c > 0 ? c - 1 : 0))}>-</button>
      <button onClick={() => setCount(c => c + 1)}>+</button>
      <button onClick={() => setCount(0)}>Reset</button>
    </div>
  );
}

export default Counter;

Reactinterview questions & answers

10 sample questions below — 174+ in the full bank inside.

&& operator JavaScript me kaise kaam karta hai jo conditional rendering possible banata hai?

&& pehle left side evaluate karta hai; agar wo falsy hai to short-circuit ho jaata hai aur wahi falsy value return kar deta hai, right side ko evaluate kiye bina. Agar left truthy hai, to right side evaluate hoke return hota hai. JSX me {cond && <Comp/>} tabhi <Comp/> render karta hai jab cond truthy ho, warna React falsy value ko skip kar deta hai.

In simple terms: Yeh security checkpoint jaisa hai — pehla check fail hua to doosre gate tak pahunchte hi nahi, aur jo pehle check me fail hua wahi report hota hai. Jaise {isAdmin && <AdminPanel/>} — agar isAdmin false hai, JavaScript <AdminPanel/> ko dekhta hi nahi, bas false return kar deta hai aur React kuch nahi dikhata.

Conditional rendering ke liye ternary aur && operator me se kab kaunsa use karein?

Ternary (cond ? A : B) tab use karo jab do me se ek cheez render karni ho (either/or). && (cond && A) tab use karo jab ya to kuch dikhana ho ya kuch bhi nahi — koi 'else' branch nahi hoti.

In simple terms: Ternary do darwazon jaisa hai — hamesha ek se guzarte ho. && ek lock lagе darwaze jaisa hai — condition true hui to darwaza khulta hai aur andar ka room dikhta hai, false hui to kuch nahi dikhta. Jaise {loading ? <Spinner/> : <Content/>} (do outcomes) vs {hasNewMessages && <Badge/>} (dikhao ya kuch nahi).

Kya component ke andar props mutable hote hain? Agar prop ko directly change karne ki koshish karo to kya hota hai?

Nahi, props receiving component ke andar read-only hote hain. React expect karta hai ki component apne props ke respect me 'pure' rahe — component kabhi apne khud ke props modify nahi karta. Agar alag data chahiye, to parent se naye props maango (usually state ko upar lift karke aur re-render karke).

In simple terms: Props ek rented car jaisi hai — chala sakte ho, use kar sakte ho, lekin repaint ya engine swap nahi kar sakte; alag car chahiye to rental company (parent) ke paas wapas jaana padega. Jaise function Greeting(props) { props.name = 'Hacked'; ... } ek anti-pattern hai — props.name ko directly mutate karne se parent me reflect nahi hota aur React ke data flow assumptions toot jaate hain.

Agar ek component null return kare to kya hota hai?

React us component ke liye kuch bhi render nahi karta — koi DOM node banta hi nahi, lekin component React tree me exist karta rehta hai aur baad me props/state badalne par phir se re-render ho sakta hai.

In simple terms: Yeh us chef jaisa hai jise order mila lekin usne is round me plate pe kuch na rakhne ka faisla kiya — kitchen (React) ko pata hai order exist karta hai, bas abhi table pe khaali plate ja rahi hai. Jaise function Banner({show}) { if (!show) return null; return <div>Sale!</div>; } — show false hone par screen pe kuch nahi dikhta.

React me 'one-way data flow' ka props ke context me kya matlab hai?

Data neeche ki taraf flow karta hai: parent components props ke through child ko data dete hain, aur child kabhi bhi parent ka data seedha change nahi kar sakta. Agar child ko parent ka state affect karna hai, to parent ek callback function prop ki tarah de deta hai, aur child us function ko call karta hai — update phir bhi 'upar' parent ke through hi hota hai, child peeche pahunch ke nahi karta.

In simple terms: Isko ek nadi jaisa samjho — paani (data) sirf neeche ki taraf behta hai (parent se child), upar kabhi nahi. Agar child ko upar message bhejna hai, to nadi ko baandhta nahi; parent ne diya hua phone (callback prop) use karta hai. Jaise <Child onSave={handleSave} /> — Child props.onSave(data) call karke parent ko batata hai, lekin parent ke state me seedha nahi ghusta.

Component aur props me kya farq hai?

Component ek reusable UI block hai (Lego block jaisa). Props wo inputs hain jo tum us block me bhejte ho customise karne ke liye; ye ek taraf bahte hain (parent se child) aur child ke andar read-only hote hain.

In simple terms: Component ko rubber stamp samjho — ek baar banaya, baar-baar chhaap sakte ho. Props woh ink ya date hai jo har baar stamp karte waqt set karte ho, isliye same stamp thoda alag output deta hai. Jaise <Button label="Save" /> aur <Button label="Delete" /> — dono same Button, bas props alag.

children prop kya hai aur ise kab use karte hain?

children ek special prop hai jo component ke opening aur closing tag ke beech jo bhi nested hota hai use hold karta hai. Ye wrapper/layout components (jaise Card, Modal, Layout) banane ke liye use hota hai jinhe pehle se pata nahi hota ki wo kya content dikhayenge — wo bas {props.children} render kar dete hain jahan content aana chahiye.

In simple terms: Ek photo frame (wrapper component) samjho — use farak nahi padta tum kaunsi photo daalo, jo bhi slot karo wo bas dikha deta hai. Jaise <Card><h2>Title</h2><p>Body</p></Card> — Card ke andar props.children wo <h2> aur <p> hai, aur Card bas <div className="card">{props.children}</div> render karta hai.

React me conditional rendering kaise karte hain?

Condition ke hisaab se alag UI dikhate hain: ternary (cond ? A : B), && operator (cond && A), ya early return se. React bas jo expression bane wahi render kar deta hai.

In simple terms: Screen pe kya dikhe, uske liye if-check jaisa. User logged in hai to "Logout" dikhao, warna "Login". JSX ke andar hi cond ? A : B ya cond && A likhte ho, aur React jo nikle wahi dikhata hai. Jaise {isLoggedIn ? <Logout/> : <Login/>}.

Modern function component me prop ko default value kaise dete ho?

Props ko destructure karte waqt function signature me default parameter value use karo, jaise function Button({ size = 'md', label }) { ... }. Purana class-based defaultProps static property abhi bhi kaam karta hai lekin default parameters function components ke liye current, preferred approach hai.

In simple terms: Ye ek food order form jaisa hai jo kehta hai 'size select nahi kiya? hum default medium de denge.' Jaise function Avatar({ size = 40 }) { return <img width={size} /> } — <Avatar /> ko bina size prop ke call karo to 40 use hoga, par <Avatar size={80} /> use 80 se override kar dega.

Optional chaining (?.) us data ke conditional rendering me kaise madad karti hai jo abhi exist nahi karta?

Optional chaining nested properties ko safely padhne deti hai jo null/undefined ho sakti hain, bina crash kiye — wo undefined return kar deti hai crash karne ki bajaye, jise phir && ya fallback (?? / ternary) ke saath combine karke conditionally render kar sakte ho.

In simple terms: Yeh darwaze pe dastak dekar politely check karne jaisa hai ki koi ghar pe hai ya nahi, bina yeh assume kiye ki room exist karta hai aur seedha andar ghus jaana (jo crash kar deta hai agar nahi ho). Jaise {user?.address?.city && <p>{user.address.city}</p>} crash nahi karega chahe user ya address abhi tak null ho jab tak data load ho raha ho.

164+ more React questions inside

Create a free account to read the full question bank, learn every topic, and practise with an AI mock interview.

Unlock all questions — free

Ready to practise React?

Unlock every topic free, then face an AI interviewer that asks follow-ups and grades your answers.

React Interview Questions & Answers | Hirenix