Skip to content

useCounter ​

utilities
test coverage
Last changed: 28 days ago

Hook that manages a counter

typescript
import { useCounter } from '@siberiacancode/reactuse';

Usage ​

typescript
const { count, dec, inc, reset, set } = useCounter(5);
// or
const { count, dec, inc, reset, set } = useCounter({ initialValue: 5, min: 0, max: 10 });

Demo ​

Api ​

Parameters

NameTypeDefaultNote
initialValue?number0The initial number value
options.min?numberNumber.NEGATIVE_INFINITYThe min of count value
options.max?numberNumber.POSITIVE_INFINITYThe max of count value

Parameters

NameTypeDefaultNote
params.initialValue?number0The initial number value
params.min?numberNumber.NEGATIVE_INFINITYThe min of count value
params.max?numberNumber.POSITIVE_INFINITYThe max of count value

Source ​

Source • Demo

Contributors ​

Avatardebabin
Avatarhywax

Released under the MIT License.