Create custom hooks 1 by anonymous

public
1 month ago
import { useState } from 'react';

export default function useCounter() {
  const [counter, setCounter] = useState(0);

  return {
    counter,
    increment: (value: number = 1) => setCounter(counter + value),
    decrement: (value: number = 1) => setCounter(counter - value),
  };
}