> ## Documentation Index
> Fetch the complete documentation index at: https://chahine.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# PNCounter

> Increment and decrement counter. Ideal for inventory, vote tallies.

A PNCounter (Positive-Negative Counter) supports both increments and decrements. Internally it uses two GCounters — one for increments, one for decrements. The value is `increments - decrements`.

## Usage

```ts theme={null}
const stock = client.pncounter("pn:product-42-stock");

// Increment / decrement
stock.increment(10);
stock.decrement(3);

// Read
console.log(stock.value()); // number (can be negative)

// Subscribe
const unsub = stock.onChange(v => console.log("stock:", v));
unsub();
```

## API

| Method | Description |
| - | - |
| `increment(amount?: number)` | Add `amount` (default 1, must be > 0) |
| `decrement(amount?: number)` | Subtract `amount` (default 1, must be > 0) |
| `value()` | Returns `increments - decrements` |
| `onChange(fn)` | Subscribe — returns unsubscribe function |
| `stream()` | Returns an Effect `Stream<number>` that emits on every change |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.