cf.completefrontend

ConceptEasy

What is an updater function, like setCount((c) => c + 1), and when do you need one instead of a value?

The code
function Basket() {
  const [count, setCount] = useState(0);
 
  function add(amount) {
    setCount(count + amount);
  }
 
  function handleAddPair() {
    add(1);
    add(1);
  }
 
  return <button onClick={handleAddPair}>Items: {count}</button>;
}

Practice it in the editor, with tests

The answer

Answer it out loud first, the way you would in the interview. Then compare.

Checking your sign-in…