airair
All questions

How many times does the initializer run

NewQuizReactmedium~3 minuseState, lazy initializer, performance
function expensive() {
  console.log("computing");
  return 42;
}

function A() {
  const [value] = useState(expensive());
  return <p>{value}</p>;
}

function B() {
  const [value] = useState(expensive);
  return <p>{value}</p>;
}

Each component mounts and then re-renders 3 more times because of a parent update. How many times does "computing" log for A and for B?

Choose one answer