Skip to content
usefy

useCounter

State & data

A lightweight, type-safe React hook for counter state management

Install

$ npm install @usefy/use-counter

Quick start

useCounter.tsx
import { useCounter } from "@usefy/use-counter";

function Counter() {
  const { count, increment, decrement, reset } = useCounter(0);

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={increment}>+</button>
      <button onClick={decrement}>-</button>
      <button onClick={reset}>Reset</button>
    </div>
  );
}

API reference

useCounter(initialValue?)

A hook that manages counter state with increment, decrement, and reset capabilities.

Parameters

ParameterTypeDefaultDescription
initialValuenumber0The initial value of the counter

Returns

PropertyTypeDescription
countnumberThe current counter value
increment() => voidIncreases the counter by 1
decrement() => voidDecreases the counter by 1
reset() => voidResets the counter to the initial value

Go deeper

This page is the quick reference. For every example, prop, and edge case, read the full README — or open Storybook to change props live.

More in state & data