Learn Quiz

React Quiz

Test your React knowledge. — 8 questions

Question 1 of 8 Score: 0

About the React Quiz

Test your React knowledge. This quiz has 8 multiple-choice questions. Each question has one correct answer, and you see an explanation straight after you answer, so you learn from every question — including the ones you get wrong. There is no time limit and nothing to sign up for; your answers are not stored.

The questions follow the material in the React Fundamentals guide and the React cheatsheet. Read them first if you want to prepare, or take the quiz cold to find the gaps in what you know.

Questions in this quiz

Preview the questions below. Each answer and its explanation are hidden until you choose to reveal them, so you can still take the quiz above without spoilers.

1. Which hook manages local component state in React?

  1. useEffect
  2. useRef
  3. useState
  4. useContext
Show answer

Answer: C. useState
useState returns [value, setter]. Calling the setter updates state and triggers a re-render.

2. When does useEffect with an empty dependency array [] run?

  1. On every render
  2. Never
  3. Only once after the first render
  4. Only when props change
Show answer

Answer: C. Only once after the first render
[] means no dependencies — the effect runs once after the initial mount, similar to componentDidMount.

3. How are props passed to a child component?

  1. Through global state
  2. Through the return value
  3. As attributes in JSX
  4. Through the constructor
Show answer

Answer: C. As attributes in JSX
Props are passed as JSX attributes: <Child name="Alice" />. They are read-only inside the child component.

4. What is the key prop used for in React lists?

  1. Styling list items
  2. Sorting the list
  3. Helping React identify changed items for efficient re-rendering
  4. Accessing items by index
Show answer

Answer: C. Helping React identify changed items for efficient re-rendering
Keys must be stable and unique among siblings. They help React match elements during reconciliation.

5. What does React.Fragment (or <>) do?

  1. Creates a new context
  2. Renders children without adding an extra DOM node
  3. Memoizes a component
  4. Creates a portal
Show answer

Answer: B. Renders children without adding an extra DOM node
Fragment lets you return multiple elements without a wrapper div, keeping the rendered DOM clean.

6. How should state be updated in React?

  1. state.value = newValue
  2. this.state = { value }
  3. Call the setter function from useState
  4. Use document.setState()
Show answer

Answer: C. Call the setter function from useState
Direct mutation does not trigger re-renders. Always call the setter returned by useState.

7. What does the useMemo hook do?

  1. Subscribes to a context
  2. Creates a ref for a DOM element
  3. Caches an expensive computed value, recomputing only when deps change
  4. Memoizes a callback function
Show answer

Answer: C. Caches an expensive computed value, recomputing only when deps change
useMemo(() => expensiveCalc(), [dep]) avoids re-running the expensive function on every render.

8. What does JSX compile to?

  1. HTML strings
  2. JSON objects
  3. React.createElement() calls
  4. DOM nodes directly
Show answer

Answer: C. React.createElement() calls
Babel transforms JSX into React.createElement(type, props, ...children) calls that build the virtual DOM tree.

How to use this quiz

  • Answer every question before reading the explanations below — retrieving an answer from memory is what makes it stick.
  • Note the questions you missed and revisit the matching section of the guide or cheatsheet.
  • Retake the quiz a day or two later. Spaced repetition is one of the most reliable ways to remember technical details.

Related