← 문제 목록
중급 React 50P

stale closure 문제

3번 빠르게 클릭해도 count가 1만 증가합니다. 버그를 찾으세요:
JSX
function Counter() {
  const [count, setCount] = useState(0);

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

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

답변

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