React (Project Talk)
Components · hooks · state · architecture
0 / 15 revised
What is React? 🎯
REACT
▾
Quick Recall
Declarative, component-based UI library with virtual DOM for efficient updates
Interview pitch: "React is a declarative, component-based JavaScript library for building UIs. It uses a virtual DOM to efficiently diff and batch updates to the real DOM, minimizing expensive reflows."
Key selling points: Declarative (describe what, not how), Component reuse, Unidirectional data flow, Large ecosystem.
Virtual DOM: Lightweight JS representation of real DOM. On state change: new vDOM → diff with old vDOM → minimal real DOM patches.
Key selling points: Declarative (describe what, not how), Component reuse, Unidirectional data flow, Large ecosystem.
Virtual DOM: Lightweight JS representation of real DOM. On state change: new vDOM → diff with old vDOM → minimal real DOM patches.
JSX
REACT
▾
Quick Recall
JSX = syntactic sugar for React.createElement(); HTML-like in JS, transpiled by Babel
What it is: XML-like syntax extension that lets you write HTML-like code in JavaScript. Transpiled to React.createElement() calls.
Rules: Must return single root element (or Fragment <>), className instead of class, htmlFor instead of for, camelCase attributes, expressions in {curly braces}.
Interview: "JSX isn't HTML — it's syntactic sugar over React.createElement that makes component structure readable. Babel transpiles it to plain JS."
Rules: Must return single root element (or Fragment <>), className instead of class, htmlFor instead of for, camelCase attributes, expressions in {curly braces}.
Interview: "JSX isn't HTML — it's syntactic sugar over React.createElement that makes component structure readable. Babel transpiles it to plain JS."
Functional vs Class Components 🎯
REACT
▾
Quick Recall
Functional + hooks is the standard; class components are legacy but may appear in codebases
| Functional | Class | |
|---|---|---|
| Syntax | Plain function returning JSX | class extends React.Component |
| State | useState hook | this.state + setState |
| Lifecycle | useEffect | componentDidMount, etc. |
| this keyword | Not needed | Required (bind issues) |
| Status | Current standard | Legacy, still supported |
Props vs State 🎯
REACT
▾
Quick Recall
Props = passed in (immutable to receiver); State = owned internally (mutable via setter)
| Props | State | |
|---|---|---|
| Ownership | Parent passes down | Component owns |
| Mutability | Read-only in child | Mutable via setState/setter |
| Purpose | Configure component | Track dynamic data |
| Re-render | When parent re-renders with new props | When state setter called |
Hooks: useState & useEffect 🎯
REACT
▾
Quick Recall
useState = reactive variable; useEffect = side effects with dependency-controlled execution
useState:
Returns current value + setter. Setter triggers re-render. Use functional update for state based on previous:
useEffect:
Cleanup: Return function runs before next effect and on unmount. Use for: unsubscribe, clear timers, cancel requests.
const [count, setCount] = useState(0);Returns current value + setter. Setter triggers re-render. Use functional update for state based on previous:
setCount(prev => prev + 1)useEffect:
useEffect(() => { /* effect */ return () => { /* cleanup */ }; }, [deps]);| Dependency Array | Runs When |
|---|---|
| No array | Every render |
| [] | Mount only (like componentDidMount) |
| [a, b] | When a or b changes |
useContext & useRef
REACT
▾
Quick Recall
useContext = consume context without prop drilling; useRef = persistent mutable ref (no re-render)
useContext: Access context value directly.
Avoids passing props through every level. Provider sets value, any descendant consumes.
useRef:
Persists across renders without causing re-render. Two uses:
const theme = useContext(ThemeContext);Avoids passing props through every level. Provider sets value, any descendant consumes.
useRef:
const inputRef = useRef(null);Persists across renders without causing re-render. Two uses:
- DOM reference:
<input ref={inputRef} />theninputRef.current.focus() - Mutable instance variable: store previous value, timer IDs, etc.
useMemo & useCallback 🎯
REACT
▾
Quick Recall
useMemo = cache computed value; useCallback = cache function reference; both need dependency array
useMemo: Memoize expensive computation result.
Recomputes only when deps change.
useCallback: Memoize function reference (prevents child re-renders when passed as prop).
When to use:
const sorted = useMemo(() => items.sort(), [items]);Recomputes only when deps change.
useCallback: Memoize function reference (prevents child re-renders when passed as prop).
const handleClick = useCallback(() => setCount(c => c+1), []);When to use:
- useMemo: expensive calculations, derived data
- useCallback: functions passed to React.memo'd children
- Don't over-use — memoization has its own cost
const [state, dispatch] = useReducer(reducer, init);Component Lifecycle (Hooks Mapping)
REACT
▾
Quick Recall
Mount=useEffect(,[]) | Update=useEffect(,[deps]) | Unmount=useEffect cleanup
| Phase | Class Method | Hooks Equivalent |
|---|---|---|
| Mount | componentDidMount | useEffect(() => {}, []) |
| Update | componentDidUpdate | useEffect(() => {}, [deps]) |
| Unmount | componentWillUnmount | useEffect cleanup return |
| Error | componentDidCatch | No hook — use ErrorBoundary (class) |
Conditional Rendering, Lists & Keys 🎯
REACT
▾
Quick Recall
Keys help React identify which items changed; use stable unique IDs, never array index
Conditional: Ternary
Lists:
Why keys matter: React uses keys to match old/new elements during reconciliation. Without stable keys, React can't efficiently determine which items were added/removed/reordered.
Never use index as key when list can reorder — causes bugs with component state and poor performance.
{isAuth ? <Dashboard/> : <Login/>}, && short-circuit {items.length > 0 && <List/>}Lists:
{items.map(item => <Item key={item.id} data={item}/>)}Why keys matter: React uses keys to match old/new elements during reconciliation. Without stable keys, React can't efficiently determine which items were added/removed/reordered.
Never use index as key when list can reorder — causes bugs with component state and poor performance.
Lifting State & Prop Drilling
REACT
▾
Quick Recall
Lift state to nearest common ancestor; Context API solves deep prop drilling
Lifting state up: When siblings need shared data, move state to their parent and pass down via props.
Prop drilling problem: Passing props through many intermediate components that don't use them.
Solutions:
Prop drilling problem: Passing props through many intermediate components that don't use them.
Solutions:
- Context API: createContext + Provider + useContext
- State management library: Redux, Zustand
- Component composition: Pass children/render props to skip levels
Controlled vs Uncontrolled Components
REACT
▾
Quick Recall
Controlled = React state drives input value; Uncontrolled = DOM holds state (use ref)
Controlled: Input value bound to state.
React is single source of truth. Needed for: validation, conditional disabling, formatting.
Uncontrolled: DOM manages its own state. Access via ref.
Simpler for quick forms. File inputs are always uncontrolled.
Interview: "I default to controlled components because they give full control over form state, but for simple cases or file uploads, uncontrolled with refs works fine."
<input value={name} onChange={e => setName(e.target.value)}/>React is single source of truth. Needed for: validation, conditional disabling, formatting.
Uncontrolled: DOM manages its own state. Access via ref.
<input ref={inputRef} defaultValue="hi"/>Simpler for quick forms. File inputs are always uncontrolled.
Interview: "I default to controlled components because they give full control over form state, but for simple cases or file uploads, uncontrolled with refs works fine."
State Management: Context vs Redux vs Zustand
REACT
▾
Quick Recall
Context = simple shared state; Redux = complex app-wide state with actions; Zustand = lightweight Redux
| Context | Redux | Zustand | |
|---|---|---|---|
| Complexity | Low | High (boilerplate) | Low |
| Best for | Theme, auth, locale | Complex app state | Medium state needs |
| Performance | Re-renders all consumers | Selective subscriptions | Selective subscriptions |
| DevTools | No | Excellent | Good |
React Router Basics
REACT
▾
Quick Recall
BrowserRouter wraps app; Route maps path→component; useNavigate for programmatic nav
Key components:
BrowserRouter— wraps app, enables routingRoutes+Route— define path→component mappingsLink/NavLink— client-side navigation (no page reload)useNavigate()— programmatic navigationuseParams()— access URL parametersOutlet— renders nested child routes
React Performance 🎯
REACT
▾
Quick Recall
Re-render ≠ DOM update; memoize with React.memo/useMemo/useCallback; profile with DevTools
What causes re-renders: State change, parent re-renders, context value changes.
Optimization tools:
Optimization tools:
- React.memo: Skip re-render if props unchanged (shallow compare)
- useMemo: Cache expensive derived values
- useCallback: Stable function references for memo'd children
- Key prop: Helps reconciliation; bad keys = wasted work
- Code splitting: React.lazy + Suspense for route-level splitting
Project Architecture Template 🎯
REACT
▾
Quick Recall
Use this template to describe your React project in interviews
"Walk me through your project" template:
1. Overview: "It's a [type] app built with React on the frontend and [FastAPI/Node] on the backend. Users can [core feature]."
2. Frontend architecture: "I used a feature-based folder structure — each feature has its components, hooks, and API calls co-located. State management via [Context/Redux] for [what state]. React Router for navigation."
3. API layer: "I created a centralized API utility using axios/fetch with interceptors for auth tokens and error handling. Custom hooks like useQuery abstract data fetching with loading/error states."
4. Auth flow: "JWT-based — login returns access+refresh tokens stored in httpOnly cookies. Protected routes check auth context before rendering."
5. Key decisions: Mention 1-2 tradeoffs you made and why. Shows engineering maturity.
6. Deployment: "Frontend on Vercel/Netlify, backend on Railway/Render, DB on [provider]."
1. Overview: "It's a [type] app built with React on the frontend and [FastAPI/Node] on the backend. Users can [core feature]."
2. Frontend architecture: "I used a feature-based folder structure — each feature has its components, hooks, and API calls co-located. State management via [Context/Redux] for [what state]. React Router for navigation."
3. API layer: "I created a centralized API utility using axios/fetch with interceptors for auth tokens and error handling. Custom hooks like useQuery abstract data fetching with loading/error states."
4. Auth flow: "JWT-based — login returns access+refresh tokens stored in httpOnly cookies. Protected routes check auth context before rendering."
5. Key decisions: Mention 1-2 tradeoffs you made and why. Shows engineering maturity.
6. Deployment: "Frontend on Vercel/Netlify, backend on Railway/Render, DB on [provider]."