frontend-opensource-project / use-react-hooks

React hoooooooks๐Ÿ˜Ž
5 stars 0 forks source link

[URH-15] useInterval ์‹ ๊ทœ #28

Closed suhyeoonn closed 1 month ago

suhyeoonn commented 1 month ago

๐Ÿ‘พ Pull Request

1๏ธโƒฃ Spec

2๏ธโƒฃ ๋ณ€๊ฒฝ ์‚ฌํ•ญ

3๏ธโƒฃ ์˜ˆ์‹œ ์ฝ”๋“œ

function App() {
  const [count, setCount] = useState(0)
  const [delay, setDelay] = useState(1000)

  const clear = useInterval(() => {
    setCount(count + 1);
  }, delay);

  const handleStop = () => {
    clear()    
  }

  const handleDelay = ({target}) => {
    setDelay(target.value)
  }

  return (
    <div>
      <input type="number" value={delay} onChange={handleDelay} />
      <button onClick={handleStop}>stop</button>
      <div>
        {count}
      </div>
    </div>
  );
}

4๏ธโƒฃ ๊ด€๋ จ ๋ฌธ์„œ (์„ ํƒ ์‚ฌํ•ญ)