Skip to content

Latest commit

 

History

History
118 lines (107 loc) · 2.64 KB

File metadata and controls

118 lines (107 loc) · 2.64 KB

useCounter

useCounter is a React hook that manages a numeric counter state with increment, decrement, and reset capabilities. Optionally, you can provide minimum and maximum values to constrain the counter's range.

Interface

function useCounter(options: UseCounterOptions): UseCounterReturn;

Parameters

Return Value

Example

import { useCounter } from 'react-simplikit';

function ShoppingCart() {
  const { count, increment, decrement, reset } = useCounter({
    initialValue: 1,
    min: 1,
    max: 10,
  });

  return (
    <div>
      <span>Quantity: {count}</span>
      <button type="button" onClick={decrement}>
        -
      </button>
      <button type="button" onClick={increment}>
        +
      </button>
      <button type="button" onClick={reset}>
        Reset
      </button>
    </div>
  );
}