0% revised

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.
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."
Functional vs Class Components 🎯
REACT
▾
Quick Recall
Functional + hooks is the standard; class components are legacy but may appear in codebases
FunctionalClass
SyntaxPlain function returning JSXclass extends React.Component
StateuseState hookthis.state + setState
LifecycleuseEffectcomponentDidMount, etc.
this keywordNot neededRequired (bind issues)
StatusCurrent standardLegacy, still supported
Why hooks won: Simpler syntax, no this binding issues, better code reuse via custom hooks, easier to test.
Props vs State 🎯
REACT
▾
Quick Recall
Props = passed in (immutable to receiver); State = owned internally (mutable via setter)
PropsState
OwnershipParent passes downComponent owns
MutabilityRead-only in childMutable via setState/setter
PurposeConfigure componentTrack dynamic data
Re-renderWhen parent re-renders with new propsWhen state setter called
Interview: "Props are the component's API — how parents communicate down. State is internal data that the component manages and that drives re-renders when it changes."
Hooks: useState & useEffect 🎯
REACT
▾
Quick Recall
useState = reactive variable; useEffect = side effects with dependency-controlled execution
useState:
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 ArrayRuns When
No arrayEvery render
[]Mount only (like componentDidMount)
[a, b]When a or b changes
Cleanup: Return function runs before next effect and on unmount. Use for: unsubscribe, clear timers, cancel requests.
useContext & useRef
REACT
▾
Quick Recall
useContext = consume context without prop drilling; useRef = persistent mutable ref (no re-render)
useContext: Access context value directly. 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} /> then inputRef.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.
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
useReducer: Alternative to useState for complex state logic. const [state, dispatch] = useReducer(reducer, init);
Component Lifecycle (Hooks Mapping)
REACT
▾
Quick Recall
Mount=useEffect(,[]) | Update=useEffect(,[deps]) | Unmount=useEffect cleanup
PhaseClass MethodHooks Equivalent
MountcomponentDidMountuseEffect(() => {}, [])
UpdatecomponentDidUpdateuseEffect(() => {}, [deps])
UnmountcomponentWillUnmountuseEffect cleanup return
ErrorcomponentDidCatchNo 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 {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:
  • 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. <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
ContextReduxZustand
ComplexityLowHigh (boilerplate)Low
Best forTheme, auth, localeComplex app stateMedium state needs
PerformanceRe-renders all consumersSelective subscriptionsSelective subscriptions
DevToolsNoExcellentGood
Interview framing: "I use Context for low-frequency updates like theme/auth. For feature state that updates often, I'd reach for Zustand or Redux Toolkit to avoid unnecessary re-renders."
React Router Basics
REACT
▾
Quick Recall
BrowserRouter wraps app; Route maps path→component; useNavigate for programmatic nav
Key components:
  • BrowserRouter — wraps app, enables routing
  • Routes + Route — define path→component mappings
  • Link / NavLink — client-side navigation (no page reload)
  • useNavigate() — programmatic navigation
  • useParams() — access URL parameters
  • Outlet — renders nested child routes
Protected routes: Wrap Route with auth check component that redirects to login if not authenticated.
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:
  • 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
Reconciliation: React diffs vDOM trees. Same type = update props. Different type = unmount old, mount new. Keys help match list items. O(n) heuristic diff.
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]."