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

# useTapStorage

> Reads and writes the one document a singleton storage collection holds.

```ts theme={null}
function useTapStorage<C>(collection): TapStorageResult<TapSingletonDocument<C>>;
```

Reads and writes the one document a singleton storage collection holds.

## Type Parameters

### C

`C` *extends* `string`

## Parameters

### collection

`C`

## Returns

[`TapStorageResult`](/extensions/reference/frontend-api/Interface.TapStorageResult)\<[`TapSingletonDocument`](/extensions/reference/frontend-api/TypeAlias.TapSingletonDocument)\<`C`>>

## Remarks

The argument is a collection name from the `TapStorageMap` augmentation
`tappify extension types` writes, and the collection has to be declared with
`"singleton": true`; an id-keyed collection throws `TAP_UNKNOWN_COLLECTION`,
with the `tap.storage.<name>.list()` path in the message. `data` is `undefined`
while the first read is in flight and `null` until the document is first
written. Every storage call needs the `storage:write` scope, reads included, and
rejects with `TAP_SCOPE_MISSING` without it. A write from another mount or
another browser tab of the same install refetches this one.

## Example

```tsx theme={null}
import { TapButton, useTapStorage } from '@tappify/extension-sdk';

function CompactToggle() {
  const preferences = useTapStorage('preferences');
  return (
    <TapButton
      loading={preferences.isLoading}
      onClick={() => void preferences.patch({ compact: true })}
    >
      Compact
    </TapButton>
  );
}
```
