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
—indexDB
item key to registerinitialValue
— initial value to set, if value in theindexDB
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
4 years ago
0.3.11
4 years ago
0.3.9
4 years ago
0.3.6
4 years ago
0.3.5
4 years ago
0.3.8
4 years ago
0.3.7
4 years ago
0.3.2
4 years ago
0.3.4
4 years ago
0.3.3
4 years ago
0.3.0
4 years ago
0.3.1
4 years ago
0.2.2
4 years ago
0.2.1
4 years ago
0.1.2
4 years ago
0.2.0
4 years ago
0.1.1
5 years ago
0.1.0
5 years ago
0.0.1
5 years ago