โ† All React Flashcard Decks

useContext and useReducer 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 useContext and useReducer flashcards as text
  1. What must you create before using the useContext hook?

    Answer: A context object with React.createContext

    React.createContext creates the context object that holds the value passed down through the component tree.

  2. What does the useContext hook return?

    Answer: The nearest Provider's value prop

    useContext returns the current value from the nearest matching Context.Provider above the component.

  3. When does a component using useContext re-render?

    Answer: When the Provider's value prop changes

    React re-renders all consumers whenever the Provider's value reference changes.

  4. What is the first argument to useReducer?

    Answer: A reducer function (state, action) => newState

    useReducer takes a reducer function that receives the current state and an action, then returns the new state.

  5. What does useReducer return?

    Answer: A [state, dispatch] tuple

    useReducer returns a [state, dispatch] pair, where dispatch sends actions to the reducer.

  6. When is useReducer generally preferred over useState?

    Answer: When state transitions are complex or state depends on the previous value with multiple sub-values

    useReducer excels when state logic is complex, has multiple sub-values, or the next state depends on the previous.

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