# react-use-idb

> Use indexDB react hook

Latest version **1.0.2** (published 2019-02-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-use-idb
pnpm add react-use-idb
yarn add react-use-idb
bun add react-use-idb
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-02-21 |
| First published | 2018-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 43 |
| Author | kigiri |
| Maintainers | kigiri |
| Keywords | indexDB, react-hook |

## Links

- npm: https://www.npmjs.com/package/react-use-idb
- Repository: https://github.com/kigiri/react-use-idb
- Homepage: https://github.com/kigiri/react-use-idb#readme
- Issues: https://github.com/kigiri/react-use-idb/issues
- npm.io page: https://npm.io/package/react-use-idb

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2019-02-21
- 1.0.1 — 2018-11-05
- 1.0.0 — 2018-11-05

## README

# react-use-idb (`useIdb`)

React side-effect hook that manages a single `indexDB` item.

A drop-in remplacement over `useLocalStorage`.

## Why ?

`LocalStorage` is synchronous and as such, has [performances issues](https://hacks.mozilla.org/2012/03/there-is-no-simple-solution-for-local-storage/)

`LocalStorage` is also limited, only storing strings and does not provide a default mechanisme for serializing / deserializing your data.

Instead, we can rely on `indexDB` for structural cloning.

## Usage

```jsx
import { useIdb } from 'react-use-idb'

const Demo = () => {
  const [value, setValue] = useIdb('my-key', 'foo')

  return (
    <div>
      <div>Value: {value}</div>
      <button onClick={() => setValue('bar')}>bar</button>
      <button onClick={() => setValue('baz')}>baz</button>
    </div>
  )
}
```

## Reference

```js
useIdb(key)
useIdb(key, initialValue)
```

- `key` &mdash; `indexDB` item key to manage.
- `initialValue` &mdash; initial value to set, if value in the `indexDB` item is empty.

> Inspired by [idb-keyval](https://github.com/jakearchibald/idb-keyval)

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