โ† All React Flashcard Decks

useState 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 useState Hook flashcards as text
  1. What does the useState hook return?

    Answer: An array with a state value and a setter function

    useState returns a tuple of [currentValue, setterFunction] that you destructure.

  2. What is the initial value passed to useState used for?

    Answer: It sets the state only on the first render

    The initial value is only used during the first render; subsequent renders use the current state.

  3. Which of the following correctly initializes a counter state to 0?

    Answer: const [count, setCount] = useState(0)

    Array destructuring with both the state variable and its setter is the correct pattern.

  4. What happens if you call the setter function returned by useState with the same value as the current state?

    Answer: React bails out of the re-render

    React uses Object.is comparison; if the value hasn't changed, it bails out of re-rendering.

  5. How do you update state based on the previous state value?

    Answer: setCount(prev => prev + 1)

    Using a functional update (prev => prev + 1) ensures you always operate on the most recent state.

  6. Which of these is a valid way to lazily initialize state?

    Answer: useState(() => expensiveComputation())

    Passing a function to useState causes it to run only on the initial render, avoiding repeated expensive calls.

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