Appearance
useCounter
A basic counter with inc / dec / set / reset and optional min / max bounds
Demo
Basic Usage
tsx
import { useCounter } from '@reause/shared'
const { count, inc, dec, set, reset } = useCounter()Usage with options
tsx
import { useCounter } from '@reause/shared'
const { count, inc, dec, set, reset } = useCounter(1, { min: 0, max: 16 })Type Declarations
ts
export interface UseCounterOptions {
min?: number;
max?: number;
}
export interface UseCounterReturn {
count: number;
inc: (delta?: number) => void;
dec: (delta?: number) => void;
get: () => number;
set: (value: number) => void;
reset: (val?: number) => number;
}
export type State<T> = StateValue<T>
export function useCounter(initialValue?: State<number>, options?: UseCounterOptions): UseCounterReturn
export function useControllableState<T>(state: State<T>, options?: UseControllableStateOptions<T>): StateTuple<T>