useIndexedDB
Custom hook that provides an interface to the [
IndexedDB API](https://developer.Installation
npx sse-tool add use-indexed-db
npm install sse-hooks
Usage
import { useIndexedDB } from "./{hooks file}";
interface UserProfile {
name: string;
age: number;
}
const { setItem, getItem, data } = useIndexedDB<UserProfile>(
"myAppDB",
"profiles",
);
const saveProfile = async () => {
await setItem("user_1", { name: "Alice", age: 30 });
};
import { useIndexedDB } from "sse-hooks";
interface UserProfile {
name: string;
age: number;
}
const { setItem, getItem, data } = useIndexedDB<UserProfile>(
"myAppDB",
"profiles",
);
const saveProfile = async () => {
await setItem("user_1", { name: "Alice", age: 30 });
};
API
Parameters
| Name | Type | Description |
|---|---|---|
| databaseName | string | The name of the IndexedDB database. |
| storeName | string | The name of the object store within the database. |
| options | UseIndexedDBOptions | Configuration options for the database connection (optional). |
Return Value
Returns UseIndexedDBReturn.
An object containing the current data state, error state, loading state, and methods to interact with the database.
Changelog
No recent changes.