React Expert

1 / 80

What does it mean to lift state up, and what architectural problem does this solve?

Select the correct answer

1

Moving state into a global store so it is accessible from any component in the tree.

2

Moving shared state to the closest common ancestor so sibling components stay in sync.

3

Moving state into a ref so updates no longer trigger unnecessary re-renders of parents.

4

Moving local state into a child component so the parent re-renders less frequently overall.

What is prop drilling and what are the built-in React ways to solve it?

Select the correct answer

1

Passing props through many intermediate layers; solved only by adding Redux or another state library.

2

Re-rendering deep child trees too often; solved with useMemo and splitting into smaller components.

3

Passing props through many intermediate layers; solved with the Context API and component composition.

4

Mutating props inside children directly; solved by memoizing components with React.memo and useCallback.

What is prop drilling, and at what point does it become a problem?

Select the correct answer

1

Passing too many props to one component at once; it becomes a problem when render performance noticeably degrades

2

Passing props through many intermediate components that don't use them; it hurts maintainability at deep levels

3

Mutating props directly inside a child component; it becomes a problem once the parent re-renders and overwrites them

4

Reading props before they are defined on mount; it becomes a problem when undefined values break the first render

How does useRef differ from useState, and when should you use a ref instead of state?

Select the correct answer

1

A ref stores a mutable value that persists without causing a re-render when changed.

2

A ref behaves like state but is reserved only for storing DOM node elements.

3

A ref triggers a synchronous re-render the moment its current value is updated.

4

A ref stores derived state that recomputes automatically whenever its dependencies change.

Explain the difference between a controlled and an uncontrolled component, and in what scenario would you prefer an uncontrolled component?

Select the correct answer

1

Controlled inputs cannot be validated live; uncontrolled inputs always re-render the whole form tree on input.

2

Controlled inputs are driven by React state; uncontrolled inputs keep value in the DOM, useful for file inputs.

3

Controlled inputs need no event handlers; uncontrolled inputs require an onChange on every keystroke typed.

4

Controlled inputs keep value in the DOM; uncontrolled inputs are driven by state, useful for live validation.

When would you choose useReducer over useState, and what are the architectural trade-offs?

Select the correct answer

1

When you need asynchronous state updates that automatically batch network requests for you.

2

When state logic is complex with many sub-values or transitions, centralizing updates in one reducer.

3

When state must be shared globally across the entire app without passing any props at all.

4

When a component has only a single boolean value that toggles between two simple states.

Why must state be treated as immutable in React, and what happens if you mutate state directly instead of using a setter function?

Select the correct answer

1

React freezes all state objects; mutating directly throws a runtime error that stops the tree.

2

React compares references to detect changes; mutating directly skips re-renders and shows stale UI.

3

React deep-compares every object; mutating directly causes infinite re-render loops that crash the app.

4

React batches mutations automatically; mutating directly only delays the re-render until the next tick.

How does React handle state updates that are dependent on the previous state, and why is the functional update pattern preferred?

Select the correct answer

1

Pass the previous state as a second argument, which React merges with the new value automatically.

2

Pass an updater function receiving the previous state, ensuring correctness when updates are batched.

3

Pass a function returning a promise, ensuring updates resolve in order before the next render.

4

Pass the new value directly, which React always reads from the freshest state during batching.

What happens if you update state inside a render function or the body of a function component?

Select the correct answer

1

It schedules the update for the next tick, so the current render completes with stale data.

2

It triggers an infinite loop of re-renders, and React throws a 'too many re-renders' error.

3

It silently ignores the update because state setters only work inside event handlers and effects.

4

It updates state once but skips the next render, leaving the component showing the old value.

How do you decide whether a piece of data should be managed as state or passed as props, and what are the conceptual trade-offs?

Select the correct answer

1

Use state for data a component owns and changes over time; use props to pass that data down to children

2

Use state for data passed from parents and props for any data that a single component owns internally over time

3

Use props for data that changes often and state for static data, because props re-render faster than state ever can

4

Use state only for primitives and props only for objects, since props cannot hold mutable primitive values safely

What is the difference between a callback ref and a ref object created with useRef, and when would you use a callback ref?

Select the correct answer

1

A callback ref is a function React calls with the node on attach/detach; use it to run logic when the node changes

2

A callback ref stores its value on the .current key; use it to avoid re-renders when state changes

3

A callback ref only works on class components; use it when you cannot call the useRef hook safely

4

A callback ref returns a frozen node snapshot; use it whenever you need to read measurements that never update again

How does React handle one-way data flow, and why is this considered an advantage over two-way data binding?

Select the correct answer

1

Data flows in both directions automatically between parent and child, which keeps every component perfectly in sync

2

Data is stored globally and read by any component, so flow direction never matters and updates stay fully predictable

3

Data flows up via props while children mutate parent state directly, which removes the need for explicit callbacks

4

Data flows down via props while changes flow up via callbacks, making state updates predictable and easy to trace

Why should we use <Fragment> (or <>) instead of a <div> wrapper, and how does this impact the DOM tree and CSS selectors like flexbox?

Select the correct answer

1

Fragments add a hidden wrapper node that browsers ignore, so flexbox can still target it without breaking the layout

2

Fragments move children into a portal outside the tree, which avoids extra nodes but detaches them from flex parents

3

Fragments render a lightweight span node instead of a div, which keeps the DOM smaller while still scoping flex rules

4

Fragments group children without adding a DOM node, so layouts like flexbox apply directly to the real elements

What is the difference between State and Props in React?

Select the correct answer

1

State and props are both read-only, but only state can be shared down the tree to multiple nested child components

2

Props are private and mutable within a component, while state is read-only and passed in from a parent component

3

State is private and mutable within a component, while props are read-only and passed in from a parent

4

State and props are both mutable, but only props trigger a re-render when their underlying values actually change

What is JSX, and what does it actually compile to?

Select the correct answer

1

JSX compiles into HTML strings that React injects into the page directly

2

JSX is syntactic sugar compiled into React.createElement() calls returning objects

3

JSX is parsed natively by the browser into real DOM nodes during runtime

4

JSX is converted into template literals that React evaluates lazily later

Why must we always start Component names with a capital letter in JSX?

Select the correct answer

1

Capitalization tells the bundler to tree-shake unused components during builds

2

Lowercase names are treated as DOM tags while capitalized names map to components

3

Capital letters are required by the JavaScript class syntax used to define them

4

Lowercase names cause naming collisions with built-in React reserved keywords

What is the difference between a class component and a function component, and why has the community largely shifted to function components?

Select the correct answer

1

Function components cannot hold state, so they suit only presentational UI pieces

2

Class components are faster since they avoid recreating functions on every render

3

Class components support hooks too but require binding methods in the constructor

4

Function components use hooks for state and effects, making logic simpler to reuse

What are the different ways to conditionally render content in JSX, and what are the pitfalls of using short-circuit evaluation with values like 0?

Select the correct answer

1

Using && with 0 renders true since the expression short-circuits to a boolean

2

Using && with 0 renders nothing since React always skips falsy values silently

3

Using && with 0 renders the 0 itself because it is falsy but still a value

4

Using && with 0 throws an error because numbers cannot be rendered as JSX nodes

How does the children prop work, and how does it enable component composition?

Select the correct answer

1

The children prop is an array of sibling components rendered next to each other

2

The children prop holds references to child instances for direct method calls now

3

The content nested between a component's tags is passed as props.children to render

4

The children prop must be explicitly passed as an attribute named children always

What are Synthetic Events in React, and why does React use its own event system instead of native browser events?

Select the correct answer

1

A cross-browser wrapper over native events that normalizes behavior and enables consistent, efficient event handling

2

A separate event queue that replaces the DOM entirely so events never reach the underlying native browser elements

3

A logging layer that records every native event for debugging but otherwise behaves identically to raw browser events

4

A polyfill that adds new event types missing from older browsers while leaving existing native events fully untouched

Why does React favor composition over inheritance, and what does a compositional architecture look like?

Select the correct answer

1

Components are merged at build time into a single class, which reduces the runtime overhead of nested render trees

2

Components extend a shared base class to inherit behavior, which keeps reuse centralized and easier to reason about

3

Components are combined via props and children to reuse behavior, which is more flexible than class hierarchies

4

Components inherit state through context providers, which lets children override any parent method when it is needed

What are "Pure Components" and how do they relate to functional programming?

Select the correct answer

1

Components that re-render only when props or state change by shallow comparison

2

Components that avoid using state entirely and rely solely on context values

3

Components that automatically memoize all of their child components recursively

4

Components that never re-render after the first mount regardless of any change

How does React handle events under the hood: where does it attach event listeners, and what changed about event delegation in React 17?

Select the correct answer

1

React attaches a separate native listener to every element that has a handler set

2

React 17 removed event delegation entirely and now uses direct inline DOM handlers

3

React attaches listeners to the root container instead of document since React 17

4

React attaches listeners to window, and React 17 moved them down to document

How do the three forms of the useEffect dependency array (no array, empty array, populated array) differ in terms of when the effect runs?

Select the correct answer

1

No array runs once before mount; empty array runs after every render; populated array runs only when all values match.

2

No array runs only on unmount; empty array runs on every update; populated array runs once when any listed value resets.

3

No array runs after every paint; empty array runs twice on mount; populated array runs until its values stop changing.

4

No array runs after every render; empty array runs once after mount; populated array runs when listed values change.

What is the primary benefit of a custom hook over a standard helper function, and how do they interact with React's stateful logic?

Select the correct answer

1

They can call other hooks to encapsulate and reuse stateful logic, which ordinary helper functions are not allowed to do.

2

They isolate logic into separate files so the bundle splits cleanly, but they share the exact capabilities of helper functions.

3

They automatically re-render every consuming component on change, whereas helper functions must trigger updates manually via state.

4

They run faster than helpers because React memoizes them automatically and caches their return values between every render.

Why can't you use async functions directly inside a useEffect?

Select the correct answer

1

An async function blocks the main thread, but useEffect must run synchronously right after the browser paints the screen.

2

An async function loses access to props, but useEffect requires the callback to close over the latest state and prop values.

3

An async function cannot use await inside, but useEffect needs awaited calls to schedule the cleanup correctly.

4

An async function returns a Promise, but useEffect expects the return to be a cleanup function or undefined.

What are the main lifecycle methods of a class component, and what are their equivalents using Hooks in a function component?

Select the correct answer

1

componentDidMount maps to useState, componentDidUpdate to useMemo, and unmount to useCallback cleanup.

2

componentDidMount, componentDidUpdate, and componentWillUnmount map to a single useEffect with a dependency array and cleanup.

3

componentDidUpdate maps to useLayoutEffect only, while mount and unmount logic must stay in a separate class wrapper.

4

render maps to useEffect, componentDidMount to useRef, and unmount to a cleanup passed into useState.

What is the purpose of the cleanup function returned from useEffect, and when exactly does React run it?

Select the correct answer

1

It batches pending state updates together; React runs it after every render but just before the browser paints the screen.

2

It tears down side effects like subscriptions; React runs it before the next effect run and when the component unmounts.

3

It resets the component's state to initial values; React runs it once immediately after the very first render completes.

4

It memoizes the effect's computed result for reuse; React runs it only when the dependency array values stay the same.

What are the Rules of Hooks, and why does React enforce that hooks are called at the top level in the same order every render?

Select the correct answer

1

Call hooks only inside effects and handlers; React tracks each hook's state by the component's position within the tree.

2

Call hooks only at the top level and from React functions; React tracks each hook's state by its call order across renders.

3

Call hooks inside conditionals to skip unneeded ones; React tracks each hook's state by a unique key that you pass to it.

4

Call hooks in any order you prefer; React tracks each hook's state by the variable name you assign its returned value to.

Why can't hooks be called inside loops or conditions, and how does React track hook state internally using an array/linked list?

Select the correct answer

1

Loops break hooks because each iteration creates a brand new component instance

2

React tracks hooks by call order, so conditional calls would misalign stored state

3

Hooks use unique internal keys, allowing them to be safely called conditionally

4

React tracks hooks by their variable names, so renaming a hook resets its state

Explain the stale closure problem in useEffect. How does the dependency array solve this, and what happens if you omit a dependency?

Select the correct answer

1

Effects run before render commits; the array delays them until paint, and omitting an item makes the effect skip its cleanup phase entirely.

2

Effects capture variables from their render; adding them to the array re-runs with fresh values, while omitting one keeps stale values.

3

Effects clone state into refs; the array syncs those refs, and omitting an item causes React to throw a stale closure error at runtime.

4

Effects always read the latest variables; the array only controls re-render timing, and omitting an item simply runs the effect more often.

What is the difference between useMemo and useCallback, and when is it over-optimization to use them?

Select the correct answer

1

useMemo caches a computed value while useCallback caches a function; using them for cheap work adds overhead, not speed.

2

useMemo caches a function while useCallback caches a value; using them everywhere guarantees fewer renders and is always worth it.

3

useMemo caches API responses while useCallback caches handlers; using them on primitives stops React from re-rendering at all.

4

useMemo caches a component while useCallback caches its props; using them sparingly is risky because stale values leak into children.

Explain the concept of code splitting in React using React.lazy and Suspense, and how does it improve Time to Interactive?

Select the correct answer

1

They cache rendered HTML on the server so the client skips hydration entirely on the first load.

2

They precompile all components into one bundle so the browser parses everything faster during startup.

3

They run component code inside a web worker so the main thread stays free during initial render.

4

They split bundles so components load on demand, shrinking the initial download and reducing Time to Interactive.

How does React.memo work, and how does it differ from useMemo?

Select the correct answer

1

React.memo caches event handlers between renders; useMemo caches the component's children element tree.

2

React.memo memoizes a value across renders; useMemo memoizes a component's output between mounts.

3

React.memo deep-compares state for updates; useMemo shallow-compares props to decide on re-rendering.

4

React.memo memoizes a whole component to skip re-renders; useMemo memoizes a computed value inside one.

How does React.memo optimize performance, and what is the difference between a shallow comparison and a deep comparison in this context?

Select the correct answer

1

React.memo re-renders on any prop change; shallow and deep comparisons both apply to hook dependencies.

2

React.memo performs a deep prop comparison by default; a shallow comparison only checks primitive props.

3

React.memo compares previous and next state deeply; shallow comparison is used only for context values.

4

React.memo skips re-renders via a shallow prop comparison; a deep comparison checks nested values too.

How do you identify a performance bottleneck in a React application?

Select the correct answer

1

Profile with the React DevTools Profiler and browser performance tools to find slow or frequent renders.

2

Add console logs to every render and measure how long the browser tab takes to fully load once.

3

Increase the production bundle size limit until the warning disappears and the app stops re-rendering.

4

Count the number of components on screen, since render time grows directly with total component count.

What is virtualization (or windowing), and why is it necessary for rendering large datasets?

Select the correct answer

1

It splits the dataset across web workers so each chunk renders on a separate background thread.

2

It preloads the entire dataset into memory so scrolling never triggers any additional network requests.

3

It compresses list items into a single canvas element, reducing the total number of React components.

4

It renders only the items currently visible in the viewport, avoiding DOM nodes for off-screen data.

How does the new React Compiler (React Forget) change how we think about performance optimization, and does it make useMemo and useCallback obsolete?

Select the correct answer

1

It moves all rendering to the server at build time, so client-side memoization hooks are fully removed.

2

It forces every component to memoize by default, which means useMemo and useCallback now throw errors.

3

It replaces the virtual DOM with a compiled reactive graph, so re-renders never happen at all during runtime.

4

It auto-memoizes components and values at build time, making most manual useMemo and useCallback unnecessary.

What are the performance tradeoffs of using the Context API for frequently changing values?

Select the correct answer

1

Consumers never re-render automatically, so frequently changing values silently fail to update the UI.

2

The provider re-renders alone while consumers stay memoized, causing stale values across the tree.

3

Only the nearest consumer re-renders, but updates propagate slowly because context batches them lazily.

4

Every consumer re-renders whenever the context value changes, even if it uses an unchanged part.

How do you identify and fix "wasted" or unnecessary re-renders in a large application?

Select the correct answer

1

Wrap every component in React.memo by default, which guarantees no component ever re-renders twice.

2

Use the Profiler to spot components rendering without prop or state changes, then apply memoization.

3

Disable strict mode and reduce state updates, since most wasted renders come from double invocation.

4

Move all state into a single top-level store so child components no longer subscribe to any updates.

What are the costs of over-using React.memo, and why shouldn't we wrap every single component in it?

Select the correct answer

1

It disables hooks inside the wrapped component and breaks state across all renders

2

It permanently caches component output and prevents any future updates from rendering

3

Each memo adds prop-comparison and memory overhead that can exceed the re-render cost

4

It forces every child component to re-render whenever the parent's own state changes

What is the purpose of "Keys" in lists, and what happens if you use a random value or an index as a key?

Select the correct answer

1

Keys cache rendered items; random or index keys disable caching and force only full re-renders

2

Keys validate props; random or index keys skip validation and silently drop the invalid items

3

Keys identify items; random or index keys cause wrong reuse, state bugs, and slow updates

4

Keys sort list items; using an index sorts numerically while random values shuffle the order

What does useContext do, and how does a component subscribe to and re-render on context changes?

Select the correct answer

1

It registers an event listener on the provider and re-renders the component only when its own props change.

2

It reads a context's current value and re-renders the component whenever the nearest provider's value changes.

3

It creates a new context object and re-renders every component in the tree whenever any piece of state updates.

4

It memoizes the provider's value and re-renders only the children that are wrapped in React.memo.

When is the Context API the right choice versus simply drilling props, and what are the performance pitfalls of overusing Context?

Select the correct answer

1

Use Context for widely-shared, stable data; overusing it re-renders all consumers on any change

2

Use Context only at the root level; overusing it duplicates state and desyncs the consumer values

3

Use Context for frequently changing data; overusing it caches values and prevents needed updates

4

Use Context for deeply nested local state; overusing it blocks parent components from re-rendering

What is the Context API, and does it replace a dedicated state management library?

Select the correct answer

1

Context only works for theming and locale, so a library is always required for any other shared state

2

Context is a complete state manager that fully replaces Redux, including middleware and devtools

3

Context stores global state in a single store and re-renders only the components that subscribe to it

4

Context shares data through the tree but doesn't manage or optimize state like a dedicated library

What is the difference between useTransition and useDeferredValue, and when would you use one over the other to improve perceived performance?

Select the correct answer

1

useTransition marks a state update as non-urgent; useDeferredValue defers a value you don't control

2

useTransition debounces event handlers; useDeferredValue throttles expensive prop computations

3

useTransition runs updates in a worker thread; useDeferredValue memoizes derived values just once

4

useTransition delays rendering by a timeout; useDeferredValue caches the previous value forever

Explain Suspense for data fetching: how does it change the way we handle loading states compared to the traditional loading-spinner pattern?

Select the correct answer

1

It wraps fetch calls in try/catch and shows error boundaries instead of any loading indicators now

2

It prefetches all data at build time so components render instantly without any loading state at all

3

It polls the server on an interval and re-renders automatically when fresh data arrives each time

4

It lets components suspend while data loads, with declarative fallback UI instead of manual spinners

What is 'Concurrent Rendering', and how does it allow React to remain responsive during heavy UI updates?

Select the correct answer

1

React batches every update into a single synchronous pass that completes before any painting occurs

2

React can interrupt, pause, and resume rendering so urgent updates aren't blocked by heavy ones

3

React precompiles components into web workers so the main thread never executes any render logic

4

React renders multiple components in parallel threads to fully utilize all the available CPU cores

Explain the concept of Transitions in React 18 and how useTransition helps maintain UI responsiveness during heavy re-renders.

Select the correct answer

1

Transitions move expensive renders to a background thread, keeping the main thread entirely free

2

Transitions mark updates as non-urgent so urgent input stays responsive during heavy re-renders

3

Transitions defer all updates by a fixed delay so the browser can finish its painting first always

4

Transitions animate component mounting and unmounting to smooth out heavy layout shifts on screen

What are Error Boundaries, why can they only be implemented as Class Components, and what types of errors do they not catch?

Select the correct answer

1

Components that catch render errors below them; only classes work since no Hook exists, and event handler and async errors slip through.

2

Components that catch errors at build time; only classes work since they predate Hooks, and errors in child lifecycle methods are missed entirely.

3

Components that catch every runtime error globally; only classes work since functions cannot hold state, and event handler errors are included.

4

Components that catch network and async errors; only classes work since Hooks cannot be conditional, and render-phase errors slip through entirely.

When would you use ReactDOM.createPortal, and can you explain a scenario where the DOM hierarchy needs to differ from the React component hierarchy?

Select the correct answer

1

To render children on the server first so that hydration of nested overlays happens before the rest of the page tree.

2

To render children into a separate React root so that their state is fully isolated from the parent application tree.

3

To render children into a DOM node outside the parent, like a modal that must escape an overflow or z-index constraint.

4

To render children lazily into a hidden node so that expensive subtrees mount only when the parent becomes visible.

What are "Higher-Order Components" (HOCs) and why have they become less common since the introduction of Hooks?

Select the correct answer

1

A component that renders another component lazily; Hooks now share logic by deferring all rendering until the data has resolved.

2

A function that takes a component and returns an enhanced one; Hooks now share logic without wrapper nesting or prop collisions.

3

A class that extends another component's behavior; Hooks now share logic by letting functions inherit from parent components directly.

4

A function that merges several components into one; Hooks now share logic by combining their render output into a single element.

Explain the "Render Props" pattern.

Select the correct answer

1

A component takes a child component as a prop and clones it, injecting extra props before rendering it itself.

2

A component renders its props as plain markup automatically, so the caller never needs to define any markup.

3

A component takes a function prop and calls it with its internal state, letting the caller decide what to render.

4

A component exposes its state through context, letting any descendant read it without passing props down.

Compare the HOC pattern with the Render Props pattern, and why have both largely been replaced by Hooks?

Select the correct answer

1

Both share logic by mutating props directly, slowing renders; Hooks reuse that logic by caching results across every component.

2

Both share logic through global stores, coupling features; Hooks reuse that logic by isolating each component into its own context.

3

Both share stateful logic by wrapping components, adding tree nesting; Hooks reuse that logic without changing the component tree.

4

Both share logic only across class components, blocking reuse; Hooks reuse that logic by converting classes into functions at runtime.

What is the overall purpose of Strict Mode in React, and what does wrapping your app in it accomplish?

Select the correct answer

1

It optimizes rendering performance by skipping unnecessary updates automatically at runtime

2

It highlights potential problems in development by double-invoking certain functions

3

It enforces stricter type checking on props and state throughout production builds

4

It prevents unsafe lifecycle methods from running by blocking them entirely in production

What is the difference between useEffect and useLayoutEffect, and when would using the former cause a flicker in the UI?

Select the correct answer

1

useEffect runs after paint, useLayoutEffect runs before it; flicker happens when the effect mutates visible layout.

2

useEffect runs on the server, useLayoutEffect runs on the client; flicker happens when the effect re-subscribes to a context value.

3

useEffect runs synchronously, useLayoutEffect runs asynchronously; flicker happens when the effect updates state on every render.

4

useEffect runs before paint, useLayoutEffect runs after it; flicker happens when the effect fetches data that delays the paint.

Why does React's 'Strict Mode' double-invoke effects and reducers in development, and what kind of bugs is it trying to surface?

Select the correct answer

1

To surface slow renders and large bundles by re-running them and exposing components that take too long to mount twice.

2

To surface impure render logic and missing effect cleanup by re-running them and exposing code that isn't idempotent.

3

To surface hydration mismatches and key errors by re-running them and exposing markup that differs from the server output.

4

To surface stale closures and outdated props by re-running them and exposing values that were captured in an earlier render.

What is useId used for, and why can't you just use a random number or index to generate IDs?

Select the correct answer

1

It generates stable unique IDs consistent across server and client renders

2

It produces a hashed ID derived from a component's current props and state

3

It creates a random ID each render to guarantee globally unique element keys

4

It returns an incrementing index used to track items inside a mapped list

What is the purpose of useImperativeHandle when used with forwardRef?

Select the correct answer

1

It customizes the ref handle a parent receives, exposing chosen methods

2

It forwards a ref through a component automatically to the nearest child element

3

It memoizes a ref so its identity stays stable across every single re-render

4

It synchronizes a ref's current value with component state on each render

Explain the difference between the Virtual DOM and the real DOM, and why is the Virtual DOM considered a performance optimization?

Select the correct answer

1

The Virtual DOM is a faster browser-native DOM that renders elements directly without any diffing at all.

2

The Virtual DOM stores components on the server and syncs them down to the real DOM over the network.

3

The Virtual DOM is a lightweight in-memory tree; React diffs it to batch and minimize costly real DOM updates.

4

The real DOM is a lightweight copy that React updates first before flushing it into the Virtual DOM.

What exactly causes a React component to re-render, and does a parent re-rendering always cause all children to re-render?

Select the correct answer

1

Any DOM event triggers it; parents always re-render every child without exceptions ever

2

State or prop changes trigger it; parents re-render children unless they're memoized

3

Only direct state changes trigger it; parents never force their children to re-render

4

Context changes alone trigger it; parents re-render children only when keys change

Explain the reconciliation process: how does React's diffing algorithm decide which parts of the DOM to update?

Select the correct answer

1

It re-renders the entire DOM tree from scratch whenever any single state value changes

2

It compares element types and keys, reusing nodes and updating only differences

3

It tracks every DOM node with unique IDs and queries the browser for changed elements

4

It compares text content of all nodes and rewrites any node whose text has changed

What is the "Virtual DOM" and how does the "Diffing Algorithm" work?

Select the correct answer

1

A compiled snapshot of HTML React ships to clients to skip rendering work entirely

2

An in-memory tree React diffs against the previous one to update the real DOM

3

A parallel DOM rendered off-screen that the browser swaps in after each render cycle

4

A browser cache of past DOM states React restores whenever a component fully unmounts

What is React Fiber, and how does it differ from the old stack reconciler in terms of how it handles updates?

Select the correct answer

1

It replaces the virtual DOM with direct, synchronous mutations to the real DOM

2

It batches every network request alongside renders to reduce overall update latency

3

It enables interruptible, incremental rendering instead of synchronous, uninterruptible work

4

It compiles components ahead of time into optimized, statically rendered HTML output

What is automatic batching in React 18, and how does it change the way state updates are processed compared to older versions?

Select the correct answer

1

It defers all state updates until the browser is idle to keep the UI responsive

2

It caches state updates and replays them only when a component finally unmounts cleanly

3

It groups multiple state updates into one re-render, even inside promises and timeouts

4

It splits one large state update into several smaller renders to avoid blocking work

Explain the difference between the Render phase and the Commit phase in the Fiber architecture, and which one is interruptible.

Select the correct answer

1

Both phases are interruptible, letting React pause and resume DOM updates freely at any point in time.

2

Both phases run synchronously, so neither one can be paused once a re-render has actually begun.

3

The Commit phase computes changes and is interruptible; the Render phase applies them to the DOM synchronously.

4

The Render phase computes changes and is interruptible; the Commit phase applies them to the DOM synchronously.

Explain the difference between the Virtual DOM and the Shadow DOM. Why does React use one but not necessarily the other?

Select the correct answer

1

The Virtual DOM is React's in-memory diffing tree; the Shadow DOM is a browser encapsulation feature React skips.

2

The Shadow DOM is React's in-memory diffing tree; the Virtual DOM is a browser encapsulation feature React relies on.

3

Both are browser-native APIs for encapsulating styles, and React uses the Shadow DOM for component isolation.

4

Both are React abstractions where the Shadow DOM diffs nodes and the Virtual DOM scopes component styles.

Why does React need to traverse the entire UI tree during a re-render, and what are the performance implications of this?

Select the correct answer

1

React traverses to re-mount every node from scratch; on large trees this guarantees constant-time updates regardless of size.

2

React traverses to recompute CSS styles for each node; reconciliation cost depends solely on the stylesheet complexity.

3

React traverses to diff each node and find what changed; on large trees this reconciliation work can get expensive.

4

React traverses only changed nodes directly via the DOM; tree size therefore has no real impact on render performance.

What does the 'use client' directive actually do? Does it mean the component only renders on the client?

Select the correct answer

1

It tells the bundler to ship the component's source to the browser and never execute it on the server at all.

2

It disables React hooks within the module so the component can run safely outside the server runtime entirely.

3

It marks a boundary so the module runs as a Client Component; it still renders on the server during SSR.

4

It forces the component to skip server-side rendering entirely and only hydrate after the page fully loads.

Why is it now recommended to fetch data directly inside Server Components rather than using useEffect on the client?

Select the correct answer

1

Fetching in Server Components caches results in localStorage, letting the client reuse them across page reloads.

2

Fetching on the server avoids client-side waterfalls and ships less JavaScript and data-fetching code to the browser.

3

Server Components automatically re-run useEffect on each request, so the data stays fresher than client fetching.

4

Client-side fetching is no longer supported in React 19, so Server Components are now the only way to load data.

What is 'Hydration' in React, and why do 'Hydration Mismatch' errors occur? How does React 18/19's selective hydration improve this?

Select the correct answer

1

Hydration sends HTML back to the server for diffing; mismatches arise from CSS errors, and selective hydration merges duplicate DOM nodes automatically.

2

Hydration attaches listeners to server HTML; mismatches arise when client output differs from markup, and selective hydration hydrates regions independently.

3

Hydration re-renders the whole page on the client; mismatches arise from slow networks, and selective hydration preloads all data before rendering begins.

4

Hydration converts HTML into a Virtual DOM copy; mismatches arise from missing keys, and selective hydration delays all events until fully loaded.

What is the fundamental difference between a Server Component and a Client Component, and why can't you use useState in a Server Component?

Select the correct answer

1

Server Components render only on the server with no client runtime, so they lack the hooks and interactivity that useState needs.

2

Server Components render on the client after fetching, so useState is blocked to prevent duplicate state across the network boundary.

3

Server Components run in a sandbox without imports, so useState fails because the state object cannot be serialized to JSON safely.

4

Server Components compile to static HTML at build time, so useState is unavailable because the build step has no event loop at all.

Explain the difference between React Server Components and traditional Server-Side Rendering (SSR). Do they solve the same problem?

Select the correct answer

1

No; SSR keeps components server-only to shrink bundles, while RSC renders HTML once mainly to speed up the initial page load.

2

Yes; both render the entire app into static HTML at build time, eliminating the need for any client-side JavaScript runtime.

3

Yes; both stream components to the browser for hydration, differing only in which bundler configuration each one happens to require.

4

No; SSR renders components to HTML for initial load, while RSC keeps components server-only to shrink bundles and fetch data.

What is "Streaming SSR" and how does it improve Time to First Byte (TTFB)?

Select the correct answer

1

The server fully renders the HTML before sending, so the browser caches markup earlier, lowering TTFB across requests.

2

The server sends HTML in chunks as it renders, so the browser receives initial markup sooner, lowering TTFB.

3

The server compresses the complete HTML payload, so the browser parses markup faster, lowering TTFB on slow networks.

4

The client requests HTML in chunks on demand, so the server defers all rendering work, lowering TTFB after hydration.

How does useSyncExternalStore help in keeping React state in sync with external data sources?

Select the correct answer

1

It batches external store updates into a single state value that re-renders only when the component finally unmounts.

2

It lets components subscribe to an external store and read a consistent snapshot, avoiding tearing during concurrent rendering.

3

It caches external API responses automatically and revalidates them on a fixed interval to keep the data fresh.

4

It replaces useEffect for all side effects by deferring external reads until after the browser paints the screen.

Explain the concept of 'Actions' in React 19. How do they simplify form handling compared to the traditional useState and onSubmit pattern?

Select the correct answer

1

They convert every onSubmit handler into a Server Component so the form logic always runs on the server.

2

They replace forms with a global store that holds all input values and validates them before any submission.

3

They cache form input across navigations and resubmit it automatically whenever the network reconnects again.

4

They wrap async submissions in transitions, automatically managing pending, error, and optimistic state for you.

Why is forwardRef being deprecated in React 19, and how do we handle refs in functional components now?

Select the correct answer

1

Refs are now banned in function components entirely, so all ref-related logic must move into class components.

2

ref can now be passed as a regular prop to function components, so forwardRef is no longer needed.

3

ref must be accessed through the new useImperativeHandle hook, which fully replaces forwardRef.

4

useRef now automatically forwards itself to child components, replacing the need for any wrapper function.

What is the difference between useActionState and useFormStatus, and when would you use one over the other?

Select the correct answer

1

useActionState caches the action's result globally; useFormStatus subscribes any component to that cached result anywhere.

2

useActionState runs only on the server; useFormStatus runs only on the client to show submission progress bars.

3

useActionState manages an action's return value and pending state; useFormStatus reads the parent form's status from a child.

4

useActionState validates form fields on submit; useFormStatus resets the form once submission succeeds without errors.

What problem does the use hook solve, and how does it differ from standard hooks regarding where it can be called?

Select the correct answer

1

It creates a mutable store and, unlike other hooks, can only be called inside Server Components.

2

It memoizes expensive values and, like other hooks, cannot be used within conditionals or loops.

3

It triggers side effects after render and, like other hooks, must be called only at the top level.

4

It reads a resource like a promise or context and, unlike other hooks, can be called conditionally.

Explain how the useOptimistic hook works. Why is it better than manually managing 'loading' and 'success' states for UI responsiveness?

Select the correct answer

1

It stores loading and success flags in context so that every component can share one consistent status.

2

It shows a temporary optimistic value during an async action and reverts automatically if the action fails.

3

It preloads the next expected server response and swaps it in before the user even triggers any action.

4

It debounces rapid state updates so the UI only re-renders once the async action has finally resolved.