useCounter

Keep a number with increment, decrement, set and reset handlers, optionally clamped to a range.

This is custom React hooks, you need to follow the Basic Rules when you use it.

General

The value stays between min and max.

APIs

useCounter

const useCounter = (
  initialValue?: number,
  options?: { min?: number; max?: number },
) => [
  number,
  {
    increment: () => void
    decrement: () => void
    set: (value: number) => void
    reset: () => void
  },
]
Edit this page on GitHub