import { useState, useEffect } from 'react';

function useCounter(): number {
  const [counter, setCounter] = useState<number>(0);

  useEffect(() => {
    const interval = setInterval(
      () => setCounter((prevCounter) => prevCounter + 1),
      1000,
      []
    );
    return () => clearInterval(interval);
  }, []);

  return counter;
}

export default useCounter;
