React · Middle · Question 61 of 75

Why is this component impure?

let guestCount = 0;
function Guest() {
  guestCount++;
  return <p>Guest #{guestCount}</p>;
}

Explanation

Strict Mode renders twice in development and reveals such bugs. Pass the number as a prop or compute it from data instead.

Further reading

Problem with a question

React · Middle · question 61

Test yourself

Take the React · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz