Skip to content
tezvyn:

Top 30 Hooks Interview Questions and Answers

30 multiple-choice questions on Hooks, drawn from 30 bites out of the 59 tagged Hooks on Tezvyn. Answer them here or read straight down. Every question carries the correct option, why it is correct, and a link to the bite it came from.

30 questions. Pick an answer, or open “Show the answer” to read it.

Answers are graded in your browser. Nothing is saved, and no XP or streak is earned here. The app keeps score.

  1. Question 1 of 30

    What is the immediate effect when a useState setter function, like setCount(count + 1), is invoked?

    Show the answer

    Answer: c · React schedules a re-render of the component with the new state value.

    Calling a useState setter function tells React to schedule a re-render with the new state value, as stated by 'React schedules a re-render.' The 'count' variable in the current render's scope does not update immediately; this is a common 'footgun' where the new value is only available on the next render.

    Read the full bite: useState: Giving Components Memory

  2. Question 2 of 30

    Which of the following best describes the primary role of React's useEffect hook?

    Show the answer

    Answer: a · To synchronize the component with external systems like APIs or browser events.

    The primary role of useEffect is to synchronize a component with systems outside React's control, such as fetching data from an API or subscribing to browser events. It is explicitly stated not to be used for data transformation or handling user events, which are managed differently.

    Read the full bite: useEffect: Syncing React with the Outside World

  3. Question 3 of 30

    Why should a team not rely solely on a pre-push hook to guarantee that all tests pass before merging?

    Show the answer

    Answer: a · It is local-only, not cloned with the repository, can be skipped with --no-verify, and does not run for web or API commits.

    Pre-push hooks reside in .git/hooks and are not copied on clone, can be bypassed with --no-verify, and do not run for web or API commits, so they cannot replace server-side enforcement. Option B is a tempting misconception: --no-verify skips pre-push hooks as well as commit hooks.

    Read the full bite: Describe using a pre-push Git hook for checks and its CI limitations.

  4. Question 4 of 30

    Which pattern correctly wires a text input as a controlled component using useState?

    Show the answer

    Answer: a · Initialize useState with an empty string at the top level, bind the input value to the state variable, and update it via onChange by calling the setter with event.target.value.

    The correct pattern requires calling useState at the top level with an empty string, binding the input value to state, and updating via the setter in onChange. Option C is tempting because it mentions binding value, but calling useState conditionally violates the Rules of Hooks and direct mutation prevents React from re-rendering.

    Read the full bite: How do you use useState to track user input?

  5. Question 5 of 30

    What happens to a useEffect's cleanup and setup when a value in its dependency array changes?

    Show the answer

    Answer: a · React runs the previous cleanup with old values first, then runs setup with the new values

    React always runs the previous effect's cleanup with the old dependency values before running the new setup when a dependency changes. The most tempting distractor is wrong because cleanup is not reserved for unmount; it runs whenever dependencies change to prevent stale subscriptions or leaks.

    Read the full bite: Explain useEffect dependency array behavior for [], [deps], and omitted

  6. Question 6 of 30

    In a React component, for which scenario would using a ref be the most appropriate choice over state?

    Show the answer

    Answer: a · Holding an interval ID returned by setInterval that needs to be cleared later.

    Refs are ideal for storing mutable values that persist across renders without triggering UI updates, such as an interval ID that is never displayed. Options A, C, and D all involve data that directly affects the UI, requiring state to ensure re-renders when the values change.

    Read the full bite: React Refs: Memory Without Re-renders

  7. Question 7 of 30

    You need to increment a React state variable three times within a single event handler. Which approach produces the correct final value?

    Show the answer

    Answer: c · Call setCount(prev => prev + 1) three times sequentially

    Option C uses the functional updater so React queues each increment against the latest pending state. Option B fails because all three calls read the same closed-over value from the render snapshot, so each computes 0 + 1.

    Read the full bite: What will count be after three setCount calls in a row?

  8. Question 8 of 30

    A useEffect subscribes to an external store. When a dependency changes and the effect must re-run, when does the cleanup function execute?

    Show the answer

    Answer: d · Immediately before the effect re-runs with the new dependency values

    React runs the cleanup function immediately before re-executing an effect when dependencies change, tearing down the previous render's side effects to prevent memory leaks and stale subscriptions. The most tempting distractor assumes cleanup is only for unmount, but that ignores the re-run scenario and fails under React 18 Strict Mode, which intentionally double-invokes effects to expose missing teardown logic.

    Read the full bite: What is the purpose of the useEffect cleanup function?

  9. Question 9 of 30

    What is the key difference between useState(expensive()) and useState(() => expensive()) during re-renders?

    Show the answer

    Answer: a · The direct call executes on every render but React discards its result after mount, while the function runs only once during initialization.

    JavaScript evaluates the direct argument before React can intercept it, so expensive() wastes cycles on every render even though React throws away the result after mount; the initializer function runs only once. Option D is tempting but wrong because lazy initialization does not prevent re-renders, it only avoids repeating expensive setup work inside them.

    Read the full bite: Why pass a function to useState for expensive initial values?

  10. Question 10 of 30

    You must measure a rendered DOM element and immediately adjust a modal to prevent visual flicker. Which choice is correct?

    Show the answer

    Answer: d · useLayoutEffect, because it runs synchronously after DOM mutations but before paint, letting you correct layout before it is visible

    useLayoutEffect runs synchronously after React commits DOM changes but before the browser paints, so layout corrections happen before the user sees anything. Option C is tempting because it names the right hook but incorrectly claims it runs after paint, which would actually cause the flicker you are trying to prevent.

    Read the full bite: When would you choose useLayoutEffect over useEffect?

  11. Question 11 of 30

    How should you refactor an effect that needs the latest prop value inside a polling interval without listing that prop as a dependency?

    Show the answer

    Answer: b · Lift the prop value into a ref and read the ref inside the interval with an empty dependency array.

    Lifting the prop into a ref lets the interval read the latest value without re-subscribing, because refs are mutable and do not trigger re-renders. Disabling the rule and reading the prop directly hides the stale closure from the linter and leaves the code vulnerable to refactor hazards.

    Read the full bite: Why is exhaustive-deps critical and when can you disable it?

  12. Question 12 of 30

    Which task is the most appropriate use case for a SvelteKit server hook?

    Show the answer

    Answer: b · Initializing a database connection pool that is shared across all server-side requests.

    The card explicitly states that "startup behavior (code at the top level of a hooks file) is ideal for initializing singletons like a database connection pool." This makes initializing a shared resource like a DB pool a primary use case for server hooks. While hooks can handle custom routing (like option A), defining standard API endpoints is typically done using dedicated +server.js files, whereas hooks are more for intercepting and modifying requests or handling non-standard routing.

    Read the full bite: SvelteKit Hooks: Intercepting Requests and Events

  13. Question 13 of 30

    When is it most appropriate to extract logic into a custom React hook?

    Show the answer

    Answer: a · When multiple components require the same stateful behavior or side effects.

    Custom hooks are specifically designed to package and reuse stateful logic (like useState and useEffect) across multiple components, preventing duplication. Option D describes general component refactoring, not the specific purpose of custom hooks. Option C is explicitly stated as a scenario where custom hooks should not be used, as a standard JavaScript function is more appropriate for pure calculations.

    Read the full bite: Custom Hooks: Package Component Logic for Reuse

  14. Question 14 of 30

    Which scenario best indicates that useReducer would be a more suitable choice than useState for managing component state?

    Show the answer

    Answer: c · The state logic involves multiple interdependent transitions where the next state relies on the previous state.

    The card states useReducer is ideal "when state logic gets complicated or when the next state depends on the previous one," and for "multiple state transitions that depend on each other." For simple, independent state like a boolean toggle (Option A), useState is preferred.

    Read the full bite: The useReducer Hook: Predictable State Updates

  15. Question 15 of 30

    What is the primary reason to use useCallback for a function in React?

    Show the answer

    Answer: c · To prevent the function from being re-created in memory on every component re-render, thus stabilizing its reference.

    useCallback's main purpose is to provide a stable reference to a function across re-renders, preventing it from being re-created each time. This is crucial for optimizing child components wrapped in React.memo or when a function is a dependency of a hook like useEffect. Option B describes the purpose of useMemo, which memoizes a value, not a function instance.

    Read the full bite: React's useCallback: Cache Functions, Not Just Values

  16. Question 16 of 30

    Why does a useEffect with an empty dependency array fail to refetch when the user returns to a stacked screen?

    Show the answer

    Answer: d · The screen remains mounted, so the effect runs only once on first mount

    Pushing a screen does not unmount the one beneath it, so a mount-only effect never re-runs on return. useFocusEffect fires on each focus, which is what triggers the refetch.

    Read the full bite: Refetching data when a screen gains focus

  17. Question 17 of 30

    For which situation should you reach for useReducer instead of multiple useState hooks?

    Show the answer

    Answer: d · Coordinating several related fields that must update atomically from one action

    useReducer excels when one action must update multiple interdependent fields atomically, centralizing transition logic outside the component. Option A is a common misconception because the hook itself does not memoize child renders or improve performance without additional optimizations like React.memo.

    Read the full bite: Explain useReducer and when to prefer it over useState

  18. Question 18 of 30

    What is the primary mechanism useMemo employs to optimize React component performance?

    Show the answer

    Answer: b · It caches the result of an expensive calculation and reuses it if its dependencies remain unchanged.

    The card states useMemo caches a function's return value and reuses it if its dependencies haven't changed, preventing expensive recalculations. It does not prevent the component itself from re-rendering, which is a common misconception.

    Read the full bite: useMemo: Cache Expensive Calculations in React

  19. Question 19 of 30

    A ThemeContext.Provider wraps the entire app and passes an unmemoized object containing theme and toggleTheme. What is the main performance risk?

    Show the answer

    Answer: d · Every consumer re-renders whenever the Provider re-renders because the object reference changes each time

    React compares context values by reference, so a new object literal on every render triggers re-renders in all consumers even if the theme data is unchanged. Option A is tempting because developers often assume context supports selective subscriptions by property, but React does not optimize that way.

    Read the full bite: Use useContext to provide theme state without prop drilling

  20. Question 20 of 30

    When a useEffect with an empty dependency array sets up a setInterval that needs to log the latest component state, what is the primary benefit of using useEffectEvent?

    Show the answer

    Answer: d · It enables the setInterval's callback to access the most current state without forcing the useEffect to re-execute.

    useEffectEvent provides a stable function that, when called, always accesses the latest props and state from the component's current render, even if the useEffect it's called from has an empty dependency array and thus doesn't re-run. This directly solves the stale closure problem. Option B describes the stale closure problem itself, not the benefit of the solution. Option A describes the behavior of an empty dependency array, not the specific benefit of useEffectEvent. Option C is incorrect as useEffectEvent is used to avoid adding functions to the dependency array.

    Read the full bite: React's Stale Closure Problem in Hooks

  21. Question 21 of 30

    Which approach correctly navigates from an Axios interceptor that runs outside any React component?

    Show the answer

    Answer: c · Use a navigationRef passed to NavigationContainer and call navigate after isReady

    Hooks only work inside components, so useNavigation throws in an interceptor. A navigationRef gives non-React code a stable handle, guarded by isReady to avoid early calls.

    Read the full bite: Accessing navigation outside a screen component

  22. Question 22 of 30

    A parent computes an expensive object and defines an inline handler passed to a React.memo child. Which hook combination correctly optimizes the computation and prevents unnecessary child re-renders?

    Show the answer

    Answer: d · useMemo for the object and useCallback for the handler

    useMemo caches the computed object value, while useCallback preserves the function reference so React.memo's Object.is check sees an unchanged prop and skips the child render. Choosing useMemo for the handler confuses the two hooks because useMemo caches the returned value rather than the function reference, and omitting a hook creates a new inline function on every parent render.

    Read the full bite: Explain the difference between useMemo and useCallback

  23. Question 23 of 30

    When is useLayoutEffect the most appropriate choice over useEffect?

    Show the answer

    Answer: d · To measure a DOM element's dimensions and update its position before the user sees any intermediate layout.

    useLayoutEffect is specifically designed for scenarios where you need to read DOM layout and make synchronous updates to prevent visual flickers before the browser paints. Option D directly describes this primary use case. Option C describes useEffect, which runs asynchronously after the browser has painted.

    Read the full bite: useLayoutEffect: Synchronous Effects Before Browser Paint

  24. Question 24 of 30

    Which scenario best illustrates the primary purpose of useImperativeHandle?

    Show the answer

    Answer: c · A parent component needs to call a specific method on a child, like focus() or reset(), without exposing the child's entire DOM node.

    Option C is correct because useImperativeHandle allows a child to expose a limited, intentional API (like specific methods) to a parent via a ref, preventing the parent from accessing the child's full internal DOM or state. Option B describes an anti-pattern that useImperativeHandle is designed to prevent, as it breaks encapsulation and top-down data flow.

    Read the full bite: useImperativeHandle: Expose a Custom Ref API

  25. Question 25 of 30

    What fundamental difference distinguishes a custom hook from a HOC when reusing stateful logic in React?

    Show the answer

    Answer: b · A custom hook extracts logic into a plain function without adding nodes to the component tree.

    Custom hooks reuse stateful logic as plain functions without adding nodes to the React tree or hiding prop sources, whereas HOCs wrap components and can create wrapper hell. Option D is tempting because it echoes the common misconception that hooks are just syntactic sugar for HOCs, but they represent a fundamentally different composition mechanism.

    Read the full bite: Compare HOCs and custom hooks for sharing logic

  26. Question 26 of 30

    In a useEffect with setInterval reading a state variable, which fix removes the stale closure without leaking or duplicating timers?

    Show the answer

    Answer: b · Add the state variable to the dependency array and return a cleanup that clears the interval

    Adding the state to the dependency array and returning a cleanup that clears the interval recreates the callback with the latest value and prevents leaks. The functional updater distractor is wrong because functional updates only help inside setState, not inside intervals or event listeners where the closure remains stale.

    Read the full bite: What is a stale closure in React hooks?

  27. Question 27 of 30

    How does useTransition primarily ensure a responsive UI when handling a slow state update?

    Show the answer

    Answer: d · By allowing urgent user interactions to render immediately while the slow update proceeds in a lower-priority lane.

    useTransition creates two rendering lanes: an urgent lane for immediate feedback and a non-urgent 'transition' lane for slower updates, allowing the UI to remain interactive. Option A is incorrect because useTransition manages priority on the main thread, it does not move work to a separate background thread.

    Read the full bite: useTransition: Keep Your UI Responsive During State Changes

  28. Question 28 of 30

    Which best describes how useDeferredValue maintains UI responsiveness during an expensive update?

    Show the answer

    Answer: d · It first renders with the previous deferred value at high priority, then with the new value at low priority.

    Option D correctly describes the mechanism: React performs an immediate, high-priority render with the old deferred value to keep the UI snappy, then schedules a low-priority, interruptible render with the new value. Option A describes debouncing, which the card explicitly states useDeferredValue is not a replacement for.

    Read the full bite: useDeferredValue: Keep UI Responsive During Renders

  29. Question 29 of 30

    What critical characteristic must the getSnapshot function in useSyncExternalStore possess to ensure correct behavior and prevent issues like tearing?

    Show the answer

    Answer: d · It must return an immutable, cached value for React's comparison.

    The card states that "your getSnapshot function must return an immutable, cached value." This is crucial because React uses Object.is to compare the returned value, and a stable, cached reference allows React to efficiently determine if a re-render is truly necessary. Option C is incorrect because returning a new reference unnecessarily would cause React to re-render even if the underlying data hasn't logically changed, defeating the purpose of the comparison.

    Read the full bite: useSyncExternalStore: Safely Read from External State

  30. Question 30 of 30

    What is the primary advantage of using React Navigation's useNavigation hook compared to passing navigation props?

    Show the answer

    Answer: b · It prevents the need to pass navigation objects through multiple layers of nested components.

    The useNavigation hook directly addresses the problem of 'prop drilling' by allowing deeply nested components to access the navigation object without it being passed down through every parent. Option C is incorrect because the card explicitly states that hooks do not work in class components directly.

    Read the full bite: Escape Prop Drilling with React Navigation Hooks

Could you explain these out loud?

That is what an interview actually tests. Tezvyn gives you questions like these with what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon