← 문제 목록
중급 React 50P

setState 배치 업데이트 오해

버튼 클릭 시 count가 3이 아닌 1이 됩니다. 버그를 찾으세요:
JSX
function Counter() {
  const [count, setCount] = useState(0);

  const handleClick = () => {
    setCount(count + 1);
    setCount(count + 1);
    setCount(count + 1);
  };

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={handleClick}>+3</button>
    </div>
  );
}

답변

로그인 후 제출하기
0명 풀이 · 정답률 0%