โ† All React Flashcard Decks

useEffect Hook Flashcards

6 cards from real React practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 6 useEffect Hook flashcards as text
  1. What hook should you use instead of useEffect when you need the effect to run synchronously before the browser paints?

    Answer: useLayoutEffect

    useLayoutEffect fires synchronously after DOM mutations but before the browser paints, similar to componentDidMount.

  2. How do you fetch data on component mount using useEffect?

    Answer: useEffect(() => { fetchData(); }, [])

    You call the async function inside a non-async effect callback with an empty dependency array to fetch on mount.

  3. Why can't you directly make the useEffect callback an async function?

    Answer: Async functions return a Promise, but useEffect expects a cleanup function or nothing

    useEffect expects the callback to return either undefined or a cleanup function, not a Promise.

  4. Which dependency array value causes useEffect to run on every render?

    Answer: No array at all (omit the second argument)

    Omitting the dependency array entirely tells React the effect has no condition and should run after every render.

  5. What is a common mistake when including objects or arrays in useEffect dependencies?

    Answer: A new reference is created on each render, causing infinite re-runs

    Objects and arrays are compared by reference; a new literal on each render will always trigger the effect.

  6. How do you cancel a fetch request inside a useEffect cleanup?

    Answer: Use an AbortController and call abort() in the cleanup function

    AbortController.abort() signals the fetch to stop, and checking the signal prevents state updates after unmount.

Written and edited by , founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy