# just-storage-hooks

> Some storage hooks

Latest version **0.3.1** (published 2023-11-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install just-storage-hooks
pnpm add just-storage-hooks
yarn add just-storage-hooks
bun add just-storage-hooks
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2023-11-25 |
| First published | 2020-06-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Michael Szmadzinski |
| Maintainers | smujmaiku |

## Links

- npm: https://www.npmjs.com/package/just-storage-hooks
- Repository: https://github.com/smujmaiku/just-storage-hooks
- Homepage: https://github.com/smujmaiku/just-storage-hooks#readme
- Issues: https://github.com/smujmaiku/just-storage-hooks/issues
- npm.io page: https://npm.io/package/just-storage-hooks

## Recent versions

- 0.3.1 (latest) — 2023-11-25
- 0.2.1 — 2021-06-08
- 0.2.0 — 2021-02-25
- 0.1.6 — 2020-09-03
- 0.1.5 — 2020-07-24
- 0.1.4 — 2020-07-09
- 0.1.3 — 2020-07-08
- 0.1.2 — 2020-06-15
- 0.1.1 — 2020-06-15

## README

# Just Storage Hooks

Do you have an input or checkbox you'd like to recover after a reload?
Do you need to store your app's configuration page?

Just use storage hooks with localStorage to ensure data is fresh on the first hook call.

## Installation

`npm i just-storage-hooks`

## Methods

### useStorage

Read and write to localStorage.

Optional `mutate` function allows for storeState data to be altered before storing. This should be memo'd or unchanged between hooks.

```js
const mutate = useCallback(data => `${data}`);
const [state, storeState] = useStorage(key, mutate);
```

### useDebounceCallback

Debounce a callback when state changes. Used to avoid thrashing localStorage in the following hooks

```js
const callback = useCallback((data) => { console.log(data); });
useDebounceCallback(state, callback, 10);
```

### useStorageState

Like useState but with localStorage when first starting the effect

```js
const [state, setState] = useStorageState('key', { some: 'state' }, optionalMutate);
```

### useStorageReducer

Like useReducer but with localStorage when first starting the effect

```js
const [state, dispatch] = useStorageReducer('key', reducer, { some: 'state' }, optionalMutate);
```

## License

Copyright (c) 2021, Michael Szmadzinski. (MIT License)

---
_Source: https://npm.io/package/just-storage-hooks · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
