0.3.12 • Published 2 years ago

use-idb-keyval v0.3.12

Weekly downloads
329
License
MIT
Repository
-
Last release
2 years ago

use-idb-keyval

This is a React hook to help you use IndexedDB.

Usage

import useIdb from "use-idb-keyval";

const Demo = () => {
  const [value, setValue, resetValue] = useIdb("count", 0);

  return (
    <>
      <p>Count: {value}.</p>
      <button onClick={() => setValue(previousValue => previousValue + 1)}>Increment</button>
      <button onClick={resetValue}>Reset</button>
    </>
  );
};

When using the setter function, you can either pass a new value or a function that takes the previous value.

API

useIdb(key);
useIdb(key, initialValue);
useIdb(key, initialValue, (inititalValue) => { doSomething(initialValue});
  • key indexDB item key to register
  • initialValue initial value to set, if value in the indexDB item is empty.
  • You can pass a function as the third parameter to do a computation with the initial value.

Inspired by idb-keyval

0.3.12

2 years ago

0.3.11

2 years ago

0.3.9

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.8

3 years ago

0.3.7

3 years ago

0.3.2

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.0

3 years ago

0.3.1

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.1.2

3 years ago

0.2.0

3 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.1

4 years ago