0.3.12 • Published 4 years ago
use-idb-keyval v0.3.12
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—indexDBitem key to registerinitialValue— initial value to set, if value in theindexDBitem 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
4 years ago
0.3.11
4 years ago
0.3.9
5 years ago
0.3.6
5 years ago
0.3.5
5 years ago
0.3.8
5 years ago
0.3.7
5 years ago
0.3.2
5 years ago
0.3.4
5 years ago
0.3.3
5 years ago
0.3.0
5 years ago
0.3.1
5 years ago
0.2.2
5 years ago
0.2.1
5 years ago
0.1.2
5 years ago
0.2.0
5 years ago
0.1.1
6 years ago
0.1.0
6 years ago
0.0.1
6 years ago